Solved

Some problem with VirtualTreeView and paths

Posted on 2004-04-01
9
303 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
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!

 
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
 
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

726 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