Using the VirtualTree View grid in Delphi

Introduction

VirtualTree View is a fast, small-footprint open-source VCL control for Delphi. It's usually used to display data in a tree, but data can also be used in regular grid. Support can be found at http://support.soft-gems.net/forums.

Important: There are very few replies in the forum above, so it doesn't look like VTV has much traction these days :-/

Unlike similar controls, VTV uses small records instead of objects to hold nodes; Navigation is done through doubly-linked lists.

Setup

Just download and run the Windows installer. It will add the path to VTV, and compile the source files.

After running the installer and launching Delphi, you might get an error "Entry point not found". This might be solved by cancelling, and then, compile and install the DPK packages manually... in which case, you might get a "[Fatal Error] VirtualTreesReg.pas(8): File not found: 'Compilers.inc': If you get this, add "drive:\Program Files\Soft Gems\Virtual Treeview\Source\" to the Library path in the Environment Options, and try again. Once installed, the widgets are available in the Virtual Controls tab.

Tips

Coding

Here's how to add a row, and remove the "+" sign, ie. use the tree as a regular grid:

  1. Add a VirtualStringTree widget to a form
  2. Add this code to create an empty, root-level node:

    procedure TForm1.Button1Click(Sender: TObject);
    begin
      VirtualStringTree1.AddChild(nil);
    end;
     
  3. To add a child node to this first root-level node:

    var
      Node: PVirtualNode;
    begin
      Node:=VirtualStringTree1.AddChild(nil);
      VirtualStringTree1.AddChild(Node);
    end;
     
  4. To add 10 child nodes in one go:

    Node:=VirtualStringTree1.AddChild(nil);
    VirtualStringTree1.ChildCount[Node]:=10;
     
  5. To find the node level of the node that was clicked:

    procedure TForm1.VirtualStringTree1Click(Sender: TObject);
    var
      Node: PVirtualNode;
    begin
      Node:=VirtualStringTree1.FocusedNode;
      if not Assigned(Node) then
        Exit;

        Showmessage(IntToStr(VirtualStringTree1.GetNodeLevel(Node)));
    end;

Q&A

When compiling a project, I get "F1026 File not found: 'VirtualTrees.dcu'"

Even though Delphi has the directory in its Library Path, and virtualtrees.dcu is there :-/

Resources