1

i am trying to add small icon to VirtualTreeview in delphi2010 i have ImageList attached to VirtualTreeview using the property images

procedure TMainFrm.VSTGetImageIndex(Sender: TBaseVirtualTree;
  Node: PVirtualNode; Kind: TVTImageKind; Column: TColumnIndex;
  var Ghosted: Boolean; var ImageIndex: Integer);
var
  FileInfo: PFileInfoRec;
begin
  if Kind in [ikNormal , ikSelected] then
  begin
    if Column = 0 then
    ImageIndex :=ImageList1.AddIcon(FileInfo.FileIco);
  end;
end;

but after adding the icons look too dark:

screenshot

FileInfo Strucutre (Record with methods) filled whene i load the files so what i need is just to add the fileico from fileinfo to imagelist and display in treeview

type
  PFileInfoRec= ^TFileInfoRec;
  TFileInfoRec = record
  strict private
    vFullPath: string;
      .
      .
      .
    vFileIco : TIcon;
  public
    constructor Create(const FilePath: string);
    property FullPath: string read vFullPath;
      .
      .
      .
    property FileIco : TIcon  read vFileIco;
  end;

the constructor:

constructor TFileInfoRec.Create(const FilePath: string);
var
  FileInfo: SHFILEINFO;
begin
  vFullPath := FilePath;
    .
    .
    .
  vFileIco        := TIcon.Create;
  vFileIco.Handle := FileInfo.hIcon;
//  vFileIco.Free;
end;

so where is the probleme ? ! thanks

S.FATEH
  • 451
  • 8
  • 16
  • Looks like a problem with partial transparency. Perhaps you need to set the image list `ColorDepth` to `cd32Bit`. – David Heffernan Jun 19 '12 at 10:23
  • @DavidHeffernan thanks but still doesn't work – S.FATEH Jun 19 '12 at 10:28
  • OK, what exactly did you do? When precisely did you change the `ColorDepth`? Immediately after creating the image list. Also, what does your real code look like? Presumably the real code assigns `FileInfo`. If the real code does so then it's disappointing that you posted fake code. If this is your real code then not assigning anything to `FileInfo` is clearly a problem. – David Heffernan Jun 19 '12 at 10:35
  • 1
    And you mustn't add a new icon every time the tree view asks for the image index. Add the icon once and return the same image index every time. – David Heffernan Jun 19 '12 at 10:41
  • David has right, you have to understand the virtual paradigm before working with Virtual TreeView. – hubalazs Jun 19 '12 at 11:31

1 Answers1

2

Let's have an image list ImageList1 and assign it to VirtualStringTree1.Images property. Then joining to the previous commenters, before you use FileInfo, assign something to it, like: FileInfo := Sender.GetNodeData(Node), than you can use FileInfo.FileIco. But you should add your icon to the imagelist not in the OnGetImageIndex. You should do it in OnInitNode (if you follow the virtual paradigm, what you should do), than store the index of the added icon in FileInfo. example:

procedure TForm1.VirtualStringTree1InitNode(Sender: TBaseVirtualTree;
  ParentNode, Node: PVirtualNode; var InitialStates: TVirtualNodeInitStates);
var
  FileInfo: PFileInfoRec;
begin
  FileInfo := Sender.GetNodeData(Node);
  //...
  FileInfo.FileIcoIndex := ImageList1.AddIcon(FileInfo.FileIco);

end;

than in onGetImageIndex:

procedure TMainFrm.VSTGetImageIndex(Sender: TBaseVirtualTree;
  Node: PVirtualNode; Kind: TVTImageKind; Column: TColumnIndex;
  var Ghosted: Boolean; var ImageIndex: Integer);
var
  FileInfo: PFileInfoRec;
begin
  FileInfo := Sender.GetNodeData(Node);
  if Kind in [ikNormal , ikSelected] then
  begin
    if Column = 0 then
    ImageIndex :=FileInfo.FileIcoIndex;
  end;
end;

If it's not adequate, please post more sample code, to enlighten us about your problem.

TLama
  • 75,147
  • 17
  • 214
  • 392
balazs
  • 5,698
  • 7
  • 37
  • 45