Solved

Some problem with VirtualTreeView and paths

Posted on 2004-04-01
9
293 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 24

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 24

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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
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 24

Author Comment

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

Regards,
   Tomas Helgi
0
 
LVL 24

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 24

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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

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 Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

707 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

13 Experts available now in Live!

Get 1:1 Help Now