Solved

Recursing Treeview nodes

Posted on 2004-08-22
3
307 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
  • 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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

706 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now