Board index » delphi » Request example of using .DATA in TreeNode (Delphi 4 Std)

Request example of using .DATA in TreeNode (Delphi 4 Std)

Hi,

Can anyone help me help with an example of assigning (and retrieving) data
to (and from) a treenode using the .DATA property.

Thanks

Paul.

 

Re:Request example of using .DATA in TreeNode (Delphi 4 Std)


var
    node : TTreenode;
    myObject : TMyObject;
begin
    myObject:=TMyObject.create;
    myObject.name:='Julias Caesar';
    myObject.age:=10;
    treeview.items.addobject(nil,myObject);{nil means add as the root}
end;

var
       myObject : TMyObject;
begin

--
Greg Lorriman
Handy, free utils at http://www.lorriman.demon.co.uk

Quote
Paul <nos...@nospam.com> wrote in message

news:3832c045_1@newsread3.dircon.co.uk...
Quote
> Hi,

> Can anyone help me help with an example of assigning (and retrieving) data
> to (and from) a treenode using the .DATA property.

> Thanks

> Paul.

Re:Request example of using .DATA in TreeNode (Delphi 4 Std)


Didn't get the second method in there :

assuming that each node has a TMyObject data property :

procedure tform1.dosomethingwithdataofnode( node : TTreeNode);
var
       myObject : TMyObject;
begin
    {this}
    showmessage(TMyObject(mode.data).name);

{or (the same)}
    myObject:=TMyObject(node.data);
    showmessage(myObject.name);
end;

Notice the typecast (since data is just a pointer and delphi needs to be
told what the pointer is pointing to). Lookup typecasting in the manual (on
the Cd in pdf format - you need the language guide).

--

--
Greg Lorriman
Handy, free utils at http://www.lorriman.demon.co.uk

Quote
Paul <nos...@nospam.com> wrote in message

news:3832c045_1@newsread3.dircon.co.uk...
Quote
> Hi,

> Can anyone help me help with an example of assigning (and retrieving) data
> to (and from) a treenode using the .DATA property.

> Thanks

> Paul.

Re:Request example of using .DATA in TreeNode (Delphi 4 Std)


In article <3832d91...@nnrp1.news.uk.psi.net>, "Greg Lorriman"

Quote
<greg.lorri...@zygon.com> writes:
>begin
>    myObject:=TMyObject.create;
>    myObject.name:='Julias Caesar';
>    myObject.age:=10;
>    treeview.items.addobject(nil,myObject);{nil means add as the root}

I think you meant :-

    treeview.items.addobject(nil, 'First Node', myObject);{nil means add as the
root}

Quote
>end;

The Data is a DWord which can have any value, usually used as a pointer to an
object or record, but can be an integer (typecast in and out) from anything.

This Data is rather like the Object in a TStringList or a Tag in any control.

If the data is an object or a record, dont forget to run through the TTreeView
freeing the memory used for this object or record, before you free the
TTreeView.

Alan Lloyd
alangll...@aol.com

Other Threads