Solved

Recursing Treeview nodes

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Why does formely good SQL code in Delphi 2009 not work under Windows 10? 5 87
Delphi selector screen 2 69
Delphi 2 47
TEMBEDDEDWB how can i change its user agent ? 8 47
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

911 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

17 Experts available now in Live!

Get 1:1 Help Now