I use last TPngComponents "PngComponents for Delphi 2009 - Delphi 10.2 Tokyo". Create simple project to show my problem.
Why after the second assign TPngImageCollectionItem object TreeView still paint first assigned image and may be need call some refresh functions?
type
TForm1 = class(TForm)
pilTree: TPngImageList;
pilNoImage: TPngImageList;
pilAllCor: TPngImageList;
tvCor: TTreeView;
pilAllNotCor: TPngImageList;
tvNoCor: TTreeView;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
procedure AddNodes(ATV: TTreeView);
var
nFirst, nChild: TTreeNode;
begin
nFirst := ATV.Items.AddChild(nil, '1');
nChild := ATV.Items.AddChild(nFirst,'2');
nChild.ImageIndex := 1;
nChild.SelectedIndex := 1;
nFirst.Expanded := True;
end;
procedure TForm1.FormCreate(Sender: TObject);
var
iI: Integer;
ItemAdd: TPngImageCollectionItem;
ANode: TTreeNode;
begin
// Steps working correct
for iI := 0 to 1 do begin
ItemAdd := pilAllCor.PngImages.Add;
ItemAdd.Assign(pilTree.PngImages[iI]);
end;
// Steps working NOT correct
for iI := 0 to 1 do begin
ItemAdd := pilAllNotCor.PngImages.Add;
ItemAdd.Assign(pilNoImage.PngImages[0]);
ItemAdd.Assign(pilTree.PngImages[iI]);
end;
//Setup treeview
tvCor.Images := pilAllCor;
tvNoCor.Images := pilAllNotCor;
AddNodes(tvCor);
AddNodes(tvNoCor);
end;
Example:
The way to add a TPngImage to a TPngImageList is using AddPng and not fiddling around with the collection. This will also update the underlying Windows image list responsible for the actual display of the image.
The correct code should look like:
If you want to change an existing item you should assign the PngImage property of the collection item: