unit Unit1;
interface
uses
Winapi.Windows,
Winapi.Messages, System.SysUtils, System.Variants, System.Classes,
Vcl.Graphics,
Vcl.Controls,
Vcl.Forms,
Vcl.Dialogs,
Vcl.StdCtrls,
Vcl.Buttons,
VirtualTrees,
Vcl.ImgList;
type
TForm2 =
class(TForm)
ImageList1: TImageList;
VST: TVirtualStringTree;
BitBtn1: TBitBtn;
procedure BitBtn1Click(Sender: TObject);
procedure VSTGetImageIndexEx(Sender: TBaseVirtualTree; Node: PVirtualNode; Kind: TVTImageKind; Column: TColumnIndex;
var Ghosted: Boolean;
var ImageIndex: TImageIndex;
var ImageList: TCustomImageList);
procedure VSTGetNodeDataSize(Sender: TBaseVirtualTree;
var NodeDataSize: Integer);
procedure VSTGetText(Sender: TBaseVirtualTree; Node: PVirtualNode;
Column: TColumnIndex; TextType: TVSTTextType;
var CellText:
string);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
type
MyThread =
class(TThread)
private
i:integer;
{ Private-Deklarationen }
protected
{ protected-Deklarationen }
procedure Execute;
override;
procedure DoSomething;
public
{ Public-Deklarationen }
end;
type
PTreeData = ^TTreeData;
TTreeData =
packed record
Column0:
String; Column1:
String; Column2:
String;
end;
var
MyThr: MyThread;
Form2: TForm2;
implementation
{$R *.dfm}
procedure MyThread.Execute;
var
Data: PTreeData;
XNode: PVirtualNode;
begin
while not Terminated
do
begin
inc(i);
XNode := form2.VST.AddChild(
nil);
if form2.VST.AbsoluteIndex(XNode) > -1
then
begin
Data := form2.VST.GetNodeData(Xnode);
Data^.Column0 := inttostr(i);
Data^.Column1 := '
Wert 1';
Data^.Column2 := '
Wert 2';
end;
if i = 10
then begin
i:=0;
SuspendThread(MyThr.Handle);
end;
Synchronize(DoSomething);
end;
end;
procedure MyThread.DoSomething;
begin
//
end;
procedure TForm2.BitBtn1Click(Sender: TObject);
begin
MyThr := MyThread.Create(True);
MyThr.FreeOnTerminate := true;
MyThr.Priority := tpIdle;
ResumeThread(MyThr.Handle);
end;
procedure TForm2.VSTGetImageIndexEx(Sender: TBaseVirtualTree; Node: PVirtualNode; Kind: TVTImageKind; Column: TColumnIndex;
var Ghosted: Boolean;
var ImageIndex: TImageIndex;
var ImageList: TCustomImageList);
begin
if Column = 0
then
begin
if Kind
in [ikNormal, ikSelected]
then ImageIndex := 0;
end;
end;
procedure TForm2.VSTGetNodeDataSize(Sender: TBaseVirtualTree;
var NodeDataSize: Integer);
begin
NodeDataSize := SizeOf(TTreeData);
end;
procedure TForm2.VSTGetText(Sender: TBaseVirtualTree; Node: PVirtualNode; Column: TColumnIndex; TextType: TVSTTextType;
var CellText:
string);
var
Data: PTreeData;
begin
Data := VST.GetNodeData(Node);
case Column
of
0: CellText := Data^.Column0;
1: CellText := Data^.Column1;
2: CellText := Data^.Column2;
end;
end;
end.