我使用最后一个 TPngComponents “ PngComponents for Delphi 2009 - Delphi 10.2 Tokyo ”。创建简单的项目来展示我的问题。
为什么在第二次分配 TPngImageCollectionItem 对象 TreeView 后仍然绘制第一个分配的图像并且可能需要调用一些刷新函数?
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;
例子: