here my simple code to add filename and their associated icon to virtualtreeview
PFileInfoRec = ^TFileInfoRec;
TFileInfoRec = record
strict private
vFullPath: string;
vFileName: string;
vFileIcon: hIcon;
public
constructor Create(const FullPath: string);
property FullPath: string read vFullPath;
property FileNam : string read vFileName;
property FileIcon: hIcon read vFileIcon;
end;
after i got the icon handle using shGetFileInfo Api
procedure TMainFrm.VSTGetImageIndex(Sender: TBaseVirtualTree;
Node: PVirtualNode; Kind: TVTImageKind; Column: TColumnIndex;
var Ghosted: Boolean; var ImageIndex: Integer);
var
FileInfo: PFileInfoRec;
Icon: TIcon;
begin
FileInfo := Sender.GetNodeData(Node);
Icon := TIcon.Create;
try
Icon.Handle := FileInfo.FileIcon;
if Kind in [ikNormal , ikSelected] then
begin
if Column = 1 then ImageIndex := ImageList.AddIcon(Icon);
end;
finally
Icon.Free; //here the probelme
end;
end;
what confuse me whene remove Icon.Free; the code work fine File added with icons but when free TIcon Object the addition of the icon fail!! any one explain to me What's wrong with this code ??
Thanks for the help in advance...