Board index » delphi » Help with TTreeNode and HTreeItem in TTreeView

Help with TTreeNode and HTreeItem in TTreeView

Hello all,

I am having a nightmare time with this TTreeView control!

I have a TTreeView object which i plan to populate during run time. Problem is
that every node might have children nodes. These children nodes are then
populated with other children  through a doubclick event, which runs a query.

I need method to store a single integer, invisibly, in a tree node basically.
I tried using  ItemID : HTreeItem of TTreeNode to uniqley id each node, but
the compiler doesn't like HTreeItem.

ARGHHHHHHHHHH!!!!!!!!!!!

Any help would be greatly appreciated.

And many thanks.

PS. Please CC to Azi...@gto.net.om as I have a slow Usenet connection (what
else can go wrong!!).

 

Re:Help with TTreeNode and HTreeItem in TTreeView


Quote
> I need method to store a single integer, invisibly, in a tree node
basically.
> I tried using  ItemID : HTreeItem of TTreeNode to uniqley id each node, but
> the compiler doesn't like HTreeItem.

You can use the TTreeNode.Data property to store a pointer to whatever kind
of object you like. If you only need to store an integer you might be able to
just cast the pointer to an integer and vice-versa. I don't know if this is
possible with Delphi though. I haven't tried it.

        Dave

P.S.
        Use the OnDeleted event to free the Node.Data object when the tree is
destroyed or a node is deleted.

Re:Help with TTreeNode and HTreeItem in TTreeView


Use something similar to following:

interface
.
.
  type

  TNodeData = class
    MyNodeId : integer;
    SomeOtherInfo : string;
    .
    .
  end;
.
.
implementation

procedure addnode(stringval: string; myid: integer; other: string);
var
   newdata: TNodeData;
   newnode: TTreeNode;
begin
   newdata:=TNodeData.create;
   newdata.MyNodeId:=myid;
   newdata.SomeOtherInfo:=other;
   newnode:=TreeView1.items.addchild(TreeView1.selected,stringval);
   newnode.data:=newdata;

  {
      Be sure to free all 'newdata' objects when you are finished with
      TreeView1 or delete one of it's nodes.  

      To access the contents of 'newdata' use the following:

      ContentsOfMyNodeId:=TNodeData(newnode.data).MyNodeId;
  }
end

Nazar Aziz <azi...@gto.net.om> wrote in article
<5i6gqn$...@lana.zippo.com>...

Quote
> Hello all,

> I am having a nightmare time with this TTreeView control!

> I have a TTreeView object which i plan to populate during run time.
Problem is
> that every node might have children nodes. These children nodes are then
> populated with other children  through a doubclick event, which runs a
query.

> I need method to store a single integer, invisibly, in a tree node
basically.
> I tried using  ItemID : HTreeItem of TTreeNode to uniqley id each node,
but
> the compiler doesn't like HTreeItem.

Re:Help with TTreeNode and HTreeItem in TTreeView


Try using the AddObject and InsertObject methos of TTreeView's Items
(which is of type TTreeNodes) with an object containg the desired
integer value.

Hope this helps.

Oran

Quote
On Sun, 06 Apr 97 01:40:04 GMT, azi...@gto.net.om (Nazar Aziz) wrote:
>Hello all,

>I am having a nightmare time with this TTreeView control!

>I have a TTreeView object which i plan to populate during run time. Problem is
>that every node might have children nodes. These children nodes are then
>populated with other children  through a doubclick event, which runs a query.

>I need method to store a single integer, invisibly, in a tree node basically.
>I tried using  ItemID : HTreeItem of TTreeNode to uniqley id each node, but
>the compiler doesn't like HTreeItem.

>ARGHHHHHHHHHH!!!!!!!!!!!

>Any help would be greatly appreciated.

>And many thanks.

>PS. Please CC to Azi...@gto.net.om as I have a slow Usenet connection (what
>else can go wrong!!).

Re:Help with TTreeNode and HTreeItem in TTreeView


Quote
In article <5i6gqn$...@lana.zippo.com> azi...@gto.net.om (Nazar Aziz) writes:
>From: azi...@gto.net.om (Nazar Aziz)
>Subject: Help with TTreeNode and HTreeItem in TTreeView
>Date: Sun, 06 Apr 97 01:40:04 GMT
>Hello all,
>I am having a nightmare time with this TTreeView control!
>I have a TTreeView object which i plan to populate during run time. Problem is
>that every node might have children nodes. These children nodes are then
>populated with other children  through a doubclick event, which runs a query.
>I need method to store a single integer, invisibly, in a tree node basically.
>I tried using  ItemID : HTreeItem of TTreeNode to uniqley id each node, but
>the compiler doesn't like HTreeItem.
>ARGHHHHHHHHHH!!!!!!!!!!!
>Any help would be greatly appreciated.
>And many thanks.
>PS. Please CC to Azi...@gto.net.om as I have a slow Usenet connection (what
>else can go wrong!!).

You actually set the HasChildren Property of the TTreeNode
Of course, now you will have to use the count property to
determine whether the child nodes have actually been built.

Re:Help with TTreeNode and HTreeItem in TTreeView


For every node there is a pointer available in which you can store
everything you like.

Timo

Nazar Aziz <azi...@gto.net.om> schreef in artikel
<5i6gqn$...@lana.zippo.com>...

Quote
> Hello all,

> I am having a nightmare time with this TTreeView control!

> I have a TTreeView object which i plan to populate during run time.
Problem is
> that every node might have children nodes. These children nodes are then
> populated with other children  through a doubclick event, which runs a
query.

> I need method to store a single integer, invisibly, in a tree node
basically.
> I tried using  ItemID : HTreeItem of TTreeNode to uniqley id each node,
but
> the compiler doesn't like HTreeItem.

> ARGHHHHHHHHHH!!!!!!!!!!!

> Any help would be greatly appreciated.

> And many thanks.

> PS. Please CC to Azi...@gto.net.om as I have a slow Usenet connection
(what
> else can go wrong!!).

Other Threads