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
LVL 4
LMuadDIbAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
LMuadDIbAuthor Commented:
Thanx alot Lee_Nover :)
got it working with your help, I appreciate it =)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Languages and Standards

From novice to tech pro — start learning today.