Solved

Recursing Treeview nodes

Posted on 2004-08-22
3
314 Views
Last Modified: 2010-04-05
I want load a list of all treeview nodes from treeview.selected down into a dynamic array prior to the actual deletion.  I cant just delete the selected one because I need to work with the treenode.data^ for each one before deleting (to remove associated data in my record array).  

Any quick code to do this?

procedure ButtonDeleteClick(Sender: TObject);
var Nodes: array of TTreeNode;
begin
  //  locate children and grandchildren of Treeview.selected (never more than 3 deep from root)
  //  copy node information to local dynamic array
       // LOOP
       // Setlength +1
       // Nodes[high(nodes] := located treeview node
      // END LOOP

 { I can do this part
  //  process associated data in records
  //  prune nodes from treeview
 }
end;


Thanks

 Don
0
Comment
Question by:d32coder
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 27

Accepted Solution

by:
kretzschmar earned 125 total points
ID: 11862804
use the ondeletion-event like

procedure TForm1.TreeView1Deletion(Sender: TObject; Node: TTreeNode);
begin
  If assigned(Node.Data) then
    Dispose(PDataCacheRecord(Node.Data));
end;

meikl ;-)
0
 

Author Comment

by:d32coder
ID: 11863266
You are the bomb!!   I wish I wasn't such a rookie.

Don
0
 

Author Comment

by:d32coder
ID: 11865537
Tip for anyone reading this later.    

Treeview.items.clear;   trips the onDeletion event for each node as it clears.   I had to learn this the hard way when my other data kept vanishing when I went to refresh the treeview.   I used a gloabal flag to abort the onDeletion event when I wanted to refresh the nodes.  This solved the vanishing data problem.


Don
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

749 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