unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, VirtualTrees, ImgList;
type
TTreedataclass=class(tobject)
public
imageindex:integer;
test:integer;
FObject : TObject;
end;
TForm1 =
class(TForm)
VST: TVirtualStringTree;
Button3: TButton;
ImageList1: TImageList;
procedure VSTClick(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure VSTGetImageIndex(Sender: TBaseVirtualTree; Node: PVirtualNode;
Kind: TVTImageKind; Column: TColumnIndex;
var Ghosted: Boolean;
var ImageIndex: Integer);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function AddVSTObject(AVST: TCustomVirtualStringTree; ANode: PVirtualNode; AObject: TObject): PVirtualNode;
var Data: TTreedataclass;
begin
Result:=AVST.AddChild(ANode);
AVST.ValidateNode(Result,False);
Data:=AVST.GetNodeData(Result);
Data.FObject:=AObject;
end;
//
procedure TForm1.Button3Click(Sender: TObject);
var I: Integer; TreeObject: TTreeDataClass;
begin
VST.NodeDataSize:=SizeOf(TTreedataclass);
for I:=1
to 100
do
begin
TreeObject:=TTreeDataClass.Create;
try
TreeObject.imageindex:=I-1;
// TreeObject.TestInt:=Random(1000);
TreeObject.test:=223;
AddVSTObject(VST,
nil,TreeObject);
except
TreeObject.Free;
end;
end;
end;
procedure TForm1.VSTClick(Sender: TObject);
var Node: PVirtualNode;
begin
Node:=VST.FocusedNode;
if not Assigned(Node)
then Exit;
Showmessage(IntToStr(VST.GetNodeLevel(Node)));
end;
procedure TForm1.VSTGetImageIndex(Sender: TBaseVirtualTree; Node: PVirtualNode;
Kind: TVTImageKind; Column: TColumnIndex;
var Ghosted: Boolean;
var ImageIndex: Integer);
var
data : TTreedataclass;t0:integer;
begin
if column = 0
then
begin
Data:=VST.GetNodeData(Node);
ImageIndex := data.ImageIndex;
t0:=data.test;
end else ImageIndex := -1;
end;
end.