Advertisement
TLama

Untitled

Mar 31st, 2015
437
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 1.14 KB | None | 0 0
  1. var
  2.   MasterNode: PVirtualNode;
  3.   DetailNode: PVirtualNode;
  4. begin
  5.   // move both table cursors to the beginning
  6.   MasterTable.First;
  7.   DetailTable.First;
  8.   // clear and lock the virtual tree
  9.   VirtualTree.Clear;
  10.   VirtualTree.BeginUpdate;
  11.   try
  12.     // iterate the master table in the outer loop
  13.     while not MasterTable.Eof do
  14.     begin
  15.       // add the master table row as the root node
  16.       MasterNode := VirtualTree.AddChild(nil);
  17.       // <- fill in the data for the MasterNode here
  18.       // while we are not at the end of the detail table and the detail row is of the same ID as the master,
  19.       // add child nodes
  20.       while not DetailTable.Eof and (DetailTable.FieldByName('MasterID') = MasterTable.FieldByName('ID')) do
  21.       begin
  22.         // add a detail node as a child of the parent node added for the master table
  23.         DetailNode := VirtualTree.AddChild(MasterNode);
  24.         // <- fill in the data for the DetailNode here
  25.         // move to the next detail row
  26.         DetailTable.Next;
  27.       end;
  28.       // move to the next master row
  29.       MasterTable.Next;
  30.     end;
  31.   finally
  32.     VirtualTree.EndUpdate;
  33.   end;
  34. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement