1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
| unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, VirtualTrees;
type
TKeywordClass = class
Name : string;
Lang : string;
Freq : Integer;
Occur : Integer;
end;
type
TForm1 = class(TForm)
VirtualStringTree1: TVirtualDrawTree;
procedure FormCreate(Sender: TObject);
procedure VirtualStringTree1DrawNode(Sender: TBaseVirtualTree;
const PaintInfo: TVTPaintInfo);
private
{ Déclarations privées }
public
{ Déclarations publiques }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
var
newKeyword : TKeywordClass;
newNode : PVirtualNode;
i:Integer;
begin
VirtualStringTree1.NodeDataSize:= Sizeof(TObject);
VirtualStringTree1.TreeOptions.MiscOptions := VirtualStringTree1.TreeOptions.MiscOptions + [toCheckSupport];
VirtualStringTree1.CheckImageKind := ckXP;
for i:=0 to 100 do
begin
newKeyword := TKeywordClass.Create;
newKeyword.Name := 'Name' + IntToStr(i);
newKeyword.Lang := 'Lang'+ IntToStr(i);
newKeyword.Freq := i;
newKeyword.Occur := 10;
newNode := VirtualStringTree1.AddChild(nil,newKeyword);
newNode.CheckType := ctCheckBox;
newNode.CheckState := csCheckedNormal;
end;
end;
procedure TForm1.VirtualStringTree1DrawNode(Sender: TBaseVirtualTree;
const PaintInfo: TVTPaintInfo);
var
KeyWord : ^TKeywordClass;
begin
KeyWord := Sender.GetNodeData(PaintInfo.node);
if Sender.Selected[PaintInfo.Node] then
PaintInfo.Canvas.Font.Color:=clWhite
else
PaintInfo.Canvas.Font.Color:=clBlack;
PaintInfo.Canvas.Brush.Style:=bsClear;
case PaintInfo.Column of
1: PaintInfo.Canvas.TextOut(PaintInfo.CellRect.Left ,PaintInfo.CellRect.Top ,KeyWord.Name);
2: PaintInfo.Canvas.TextOut(PaintInfo.CellRect.Left ,PaintInfo.CellRect.Top ,KeyWord.Lang );
3: PaintInfo.Canvas.TextOut(PaintInfo.CellRect.Left ,PaintInfo.CellRect.Top ,IntToStr(KeyWord.Freq ));
4: PaintInfo.Canvas.TextOut(PaintInfo.CellRect.Left ,PaintInfo.CellRect.Top ,IntToStr(KeyWord.Occur ));
end;
end;
end. |
Partager