[Webinar] Streamline your web hosting managementRegister Today

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

using the virtual treeview...

Im new to using the component Virtual TreeView
and to be honest I cant figure it out

I have a project where I have my own record arrays and I want to be able to use the array in the virtual treeview but I am a lost.
There is an example that comes with it that is suppose to show me I think, but I cant seem to figure it out with my arrays.

Basically Im trying to create my own bookmark form for an application, and I want to use the virtual tv to display the bookmarks,
I store each property of the bookmark in an array record... the tv will only display a couple items from the record though and not all.

I have read the help files and gone through the demos for the compenent...
Anyways, can someone here show me the basics of using the virtual treeview with your own record arrays?


My project
0
LMuadDIb
Asked:
LMuadDIb
  • 2
  • 2
  • 2
1 Solution
 
sftwengCommented:
0
 
Lee_NoverCommented:
set the VTV's NodeDataSize to SizeOf(YourRecord);
adding the items the proper way: set RootNodeCount, in the OnInitNode event set the node's data, handle OnInitChildren ...
the not recommended way: VTV.AddNode(ParentNode, nodedata); (I use this as it's more readable :D)

you could do:
VTV.AddNode(nil, @TheArray[Index]);

in OnGetCellText

case ColumnIndex of
  0: CellText:=PMyRec(Sender.GetNodeData(Node)).ValueAsString;
end;

PMyRec = ^TMyRec; ... this I hope you know what it is :)
0
 
LMuadDIbAuthor Commented:
sftweng, Virtual Treeview is quite different from the standard TTreeview

Lee_Nover, can you elaborate more? esp about the pointer?

here is my record array and code:

type
  TMyRecord = record  
    Name         : string[255];
    Nick         : string[255];
    Address      : widestring;
    Description  : widestring;
    Created      : string[50];
    Visited      : string[50];
    ParentFolder : widestring;
  end;

var
  RecArrData: array[0..10] of TMyRecord;

procedure TForm1.LoadArrayIntoTV();
var
  i : integer;
begin
  {we add random info into the array then }
  { set the VTV's NodeDataSize to SizeOf(YourRecord); }
  VT.NodeDataSize := SizeOf(RecArrData);

  for i := 0 to 10 do
    VT.AddChild(nil, @RecArrData[i].Name);

end;

procedure TForm1.VTGetText(Sender: TBaseVirtualTree; Node: PVirtualNode;
  Column: TColumnIndex; TextType: TVSTTextType; var CellText: WideString);
//var
  //Data: ^rTreeData;

begin
  case Column of
    0: CellText:=PVirtualNode(Sender.GetNodeData(Node)).ValueAsString;
  end;
end;

when you stated "PMyRec = ^TMyRec;"
my record array should look like so instead of the above def, adding a pointer to the record:

type
  PVirtualNode = ^TMyRecord;
  TMyRecord = record   { RECORD FOR BOOKMARKS DUH! }
    Name         : string[255];
    Nick         : string[255];
    Address      : widestring;
    Description  : widestring;
    Created      : string[50];
    Visited      : string[50];
    ParentFolder : widestring;
    NodePointer  : PVirtualNode;
  end;


but I get incompatable types ... hmmm
sorry for the late reply, just been working alot
thanx



0
Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

 
sftwengCommented:
LMuadDIb, thanks for the clairification. I'm not familiar with it; we're using the DevExpress components.
0
 
Lee_NoverCommented:
type
  PMyRecord = ^TMyRecord;
  TMyRecord = record  
    Name         : string[255];
    Nick         : string[255];
    Address      : widestring;
    Description  : widestring;
    Created      : string[50];
    Visited      : string[50];
    ParentFolder : widestring;
  end;

var
  RecArrData: array[0..10] of TMyRecord;

procedure TForm1.LoadArrayIntoTV();
var
  i : integer;
begin
  {we add random info into the array then }
  { set the VTV's NodeDataSize to SizeOf(YourRecord); }
  VT.NodeDataSize := SizeOf(TMyRecord); // !!!
  for i := 0 to 10 do
    VT.AddChild(nil, @RecArrData[i]);

{ if you have a lot of records and have a browsable data structure then set your datasize to the size of a reference to that data
ex:
VT.NodeDataSize:=SizeOf(Integer);

//.. when adding/removing VTV nodes allways use:
VT.BeginUpdate;
try
  for (...) do
    VT.AddChild(nil, Pointer(I));
finally
  VT.EndUpdate;
end;

and in get text:
CellText:=RecArrData[Integer(Sender.GetNodeData(Node)^)].Name;

this way you only store the index of the item ..
but beware that this method is very prone to errors
you should think about classes and read some OOP docs :)

}

end;

procedure TForm1.VTGetText(Sender: TBaseVirtualTree; Node: PVirtualNode;
  Column: TColumnIndex; TextType: TVSTTextType; var CellText: WideString);
//var
  //Data: ^rTreeData;

begin
  case Column of
    0: CellText:=PMyRecord(Sender.GetNodeData(Node)).Name;
  end;
end;

> when you stated "PMyRec = ^TMyRec;"
> my record array should look like so instead of the above def, adding a pointer to the record:

a pointer to what ?

type
  PMyRecord = ^TMyRecord; // PVirtualNode is a type in VirtualTrees !!
  TMyRecord = record   { RECORD FOR BOOKMARKS DUH! }
    Name         : string[255];
    Nick         : string[255];
    Address      : widestring;
    Description  : widestring;
    Created      : string[50];
    Visited      : string[50];
    ParentFolder : widestring;
//    NodePointer  : PVirtualNode; // why ? your data never needs and never should know how it's displayed .. basics of OO MVP
  end;
0
 
LMuadDIbAuthor Commented:
Thanx alot Lee_Nover :)
got it working with your help, I appreciate it =)
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

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