[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 324
  • Last Modified:

Some problem with VirtualTreeView and paths

Hi!
I'm using Virtual TreeView from http://virtualtreeview.delphi-gems.com/VT.php.
The problem is that I have a database that has a table with 3 fields volume, path and filename.
I want to list each recordset from a query in the virtualtreeview with the volume as root and the filename as the last childnode and the path as nodes between those two and
do that for each filename in the table.
I have tried 2 different approaches with no success. :(
Can anyone give me a good solution how to do this ??

Regards,
  Tomas Helgi
0
Tomas Helgi Johannsson
Asked:
Tomas Helgi Johannsson
  • 5
  • 3
1 Solution
 
mokuleCommented:
Place on a Form
    vsTree: TVirtualStringTree;
    Button1: TButton;
    Edit1: TEdit;            // for volume text
    Edit2: TEdit;            // for path text
    Edit3: TEdit;            // for file text
-------------------------------------------------
I don't checked for identical triples volume,path,file
-------------------------------------------------

type
  PMyRec = ^TMyRec;
  TMyRec = record
    Caption: WideString;
  end;
implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
  vsTree.NodeDataSize := SizeOf(TMyRec);
  Edit1.Text := 'Volume';
  Edit2.Text := 'Path';
  Edit3.Text := 'File';
end;

procedure TForm1.vsTreeGetText(Sender: TBaseVirtualTree;
  Node: PVirtualNode; Column: TColumnIndex; TextType: TVSTTextType;
  var CellText: WideString);
var
  Data: PMyRec;
begin
  Data := Sender.GetNodeData(Node);
  if Assigned(Data) then
    begin
    CellText := Data.Caption;
    end;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  pvn: PVirtualNode;
  pvnVol: PVirtualNode;
  Data: PMyRec;
  FoundVolume: boolean;
  FoundPath: boolean;
begin
  FoundVolume := False;
  FoundPath := False;
  pvn := vsTree.GetFirst;
  while pvn <> nil do
    begin
    Data := vsTree.GetNodeData(pvn);
    if Data.Caption = Edit1.Text then
      begin
      FoundVolume := True;
      pvnVol := pvn;
      pvn := vsTree.GetFirstChild(pvn);
      while pvn <> nil do
        begin
        Data := vsTree.GetNodeData(pvn);
        if Data.Caption = Edit2.Text then
          begin
          FoundPath := True;
          break;
          end;
        pvn := vsTree.GetNextSibling(pvn);
        end;
      break;
      end;
    pvn := vsTree.GetNextSibling(pvn);
    end;
  if not FoundVolume then
    begin
    vsTree.RootNodeCount := vsTree.RootNodeCount + 1;
    pvn := vsTree.GetLast;
    Data := vsTree.GetNodeData(pvn);
    Data.Caption := Edit1.Text;

    pvn := vsTree.AddChild(pvn);
    Data := vsTree.GetNodeData(pvn);
    Data.Caption := Edit2.Text;
    pvn := vsTree.AddChild(pvn);
    Data := vsTree.GetNodeData(pvn);
    Data.Caption := Edit3.Text;
    end
  else if not FoundPath then
    begin
    pvn := vsTree.AddChild(pvnVol);
    Data := vsTree.GetNodeData(pvn);
    Data.Caption := Edit2.Text;
    pvn := vsTree.AddChild(pvn);
    Data := vsTree.GetNodeData(pvn);
    Data.Caption := Edit3.Text;
    end
  else
    begin
    pvn := vsTree.AddChild(pvn);
    Data := vsTree.GetNodeData(pvn);
    Data.Caption := Edit3.Text;
    end;
end;

0
 
Lee_NoverCommented:
there's a DB aware version of VTV in the Addons package (same page as the main distro of VTV)
try that .. it worked fine a year ago :-)
0
 
Tomas Helgi JohannssonAuthor Commented:
Thank you very much Lee Nover for pointing me in the right direction.
The DB aware version and it's functionality is what I was looking for.

Regards,
   Tomas Helgi
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Tomas Helgi JohannssonAuthor Commented:
Just one more question.
I'm little bit confused what the PathField stands for and how it fits into the picture.

Regards,
   Tomas Helgi
0
 
Lee_NoverCommented:
it's for parent/child relations in the Tree
you can have a field that stores 'c:\folder1\folder2\file1' .. the tree would then have a root node of 'c:' and a child 'folder1' with a child 'folder2' ... and so on :)
0
 
Tomas Helgi JohannssonAuthor Commented:
Great ;)
Thank you very much.

Regards,
   Tomas Helgi
0
 
Tomas Helgi JohannssonAuthor Commented:
Hmmm ok I have changed the parameters to dboPathStructure and set the PathField but I don't get any data in the Tree.
What do I have to do to make it visible (besides Opening the table ;) ???

Regards,
  Tomas Helgi
0
 
Tomas Helgi JohannssonAuthor Commented:
Lee
Could you give me an example on how to configure the Tree and program around it so that this would work.
I don't seem to be doing it right.

Best regards,
  Tomas Helgi
0
 
Lee_NoverCommented:
sorry I misslead you .. the Path in the PathFieldName must have integers joined with a period (dot)
the path represents the nodes relation thru KeyFieldName

the current version of the DBTree supports only integer and floating point values for KeyField and ParentField
it should be fairly simple to change the ID from Double to String
5-10 mins of work .. maybe if I have a bit more time I can make that change
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now