这是我将文件名及其关联图标添加到 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;
在我使用 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;
删除 Icon.Free 时让我感到困惑的是什么;代码工作正常文件添加了图标,但是当免费的 TIcon 对象添加图标失败!任何人向我解释这段代码有什么问题?
我在这里先向您的帮助表示感谢...