Advertisement
Guest User

Store data in PVirtualNode

a guest
May 13th, 2011
421
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 2.42 KB | None | 0 0
  1. unit uMain;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  7.   Dialogs, VirtualTrees;
  8.  
  9. Type
  10.   PMyRec = ^TMyRec;
  11.   TMyRec = Record
  12.     ConName, ConSkypeID, CtgName : String;
  13.     CtgID : Integer;
  14.   End;
  15.  
  16. type
  17.   TfrmMain = class(TForm)
  18.     VT: TVirtualStringTree;
  19.     procedure VTGetNodeDataSize(Sender: TBaseVirtualTree;
  20.       var NodeDataSize: Integer);
  21.     procedure VTFreeNode(Sender: TBaseVirtualTree; Node: PVirtualNode);
  22.     procedure VTGetText(Sender: TBaseVirtualTree; Node: PVirtualNode;
  23.       Column: TColumnIndex; TextType: TVSTTextType; var CellText: string);
  24.     procedure FormCreate(Sender: TObject);
  25.   private
  26.     { Private declarations }
  27.   public
  28.     { Public declarations }
  29.   end;
  30.  
  31. var
  32.   frmMain: TfrmMain;
  33.  
  34. implementation
  35.  
  36. {$R *.dfm}
  37.  
  38. procedure TfrmMain.FormCreate(Sender: TObject);
  39. Var
  40.  I, J : Integer;
  41.  ParentNode : PVirtualNode;
  42.  ParentData, ChildData : PMyRec;
  43. begin
  44.  VT.NodeDataSize := SizeOf(TMyRec);
  45.  VT.BeginUpdate;
  46.  for I := 1 to 1000 do
  47.    begin
  48.  
  49.      ParentNode := VT.AddChild(nil);
  50.      ParentData := VT.GetNodeData(ParentNode);
  51.      ParentData.CtgName := 'Category #'+IntToStr(I);
  52.      ParentData.CtgID := Random(10000);
  53.      for J := 1 to 1000 do
  54.        begin
  55.          ChildData := VT.GetNodeData(VT.AddChild(ParentNode));
  56.          ChildData.ConName := 'Some Contact';
  57.          ChildData.ConSkypeID := 'SomeSkypeID';
  58.        end;
  59.  
  60.    end;
  61.  VT.EndUpdate;
  62. end;
  63.  
  64. procedure TfrmMain.VTFreeNode(Sender: TBaseVirtualTree; Node: PVirtualNode);
  65. Var
  66.  Data : PMyRec;
  67. begin
  68.  
  69.  Data := VT.GetNodeData(Node);
  70.  
  71.  if Assigned(Data) then
  72.  begin
  73.    Data.ConName := '';
  74.    Data.ConSkypeID := '';
  75.    Data.CtgName := '';
  76.    Finalize(Data^);
  77.  end;
  78.  
  79. end;
  80.  
  81. procedure TfrmMain.VTGetNodeDataSize(Sender: TBaseVirtualTree;
  82.   var NodeDataSize: Integer);
  83. begin
  84.   NodeDataSize := SizeOf(TMyRec);
  85. end;
  86.  
  87. procedure TfrmMain.VTGetText(Sender: TBaseVirtualTree; Node: PVirtualNode;
  88.   Column: TColumnIndex; TextType: TVSTTextType; var CellText: string);
  89. Var
  90.  Data : PMyRec;
  91. begin
  92.  
  93.  Data := VT.GetNodeData(Node);
  94.  
  95.  case VT.GetNodeLevel(Node) of
  96.     0:
  97.     begin
  98.      case Column of
  99.      0: CellText := Data.CtgName;
  100.      1: CellText := IntToStr(Data.CtgID);
  101.      end;
  102.  
  103.     end;
  104.  
  105.     1:
  106.     begin
  107.       case Column of
  108.       0: CellText := Data.ConName;
  109.       1: CellText := Data.ConSkypeID;
  110.       end;
  111.     end;
  112.  
  113.  end;
  114.  
  115. end;
  116.  
  117. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement