Solved

Some problem with VirtualTreeView and paths

Posted on 2004-04-01
9
296 Views
Last Modified: 2010-04-05
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
Comment
  • 5
  • 3
9 Comments
 
LVL 17

Expert Comment

by:mokule
ID: 10736998
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
 
LVL 12

Accepted Solution

by:
Lee_Nover earned 400 total points
ID: 10738568
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
 
LVL 25

Author Comment

by:Tomas Helgi Johannsson
ID: 10744177
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
 
LVL 25

Author Comment

by:Tomas Helgi Johannsson
ID: 10744902
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 12

Expert Comment

by:Lee_Nover
ID: 10754900
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
 
LVL 25

Author Comment

by:Tomas Helgi Johannsson
ID: 10755686
Great ;)
Thank you very much.

Regards,
   Tomas Helgi
0
 
LVL 25

Author Comment

by:Tomas Helgi Johannsson
ID: 10759111
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
 
LVL 25

Author Comment

by:Tomas Helgi Johannsson
ID: 10772949
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
 
LVL 12

Expert Comment

by:Lee_Nover
ID: 10773435
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now