?
Solved

Recursing Treeview nodes

Posted on 2004-08-22
3
Medium Priority
?
316 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 500 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

Technology Partners: 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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses
Course of the Month11 days, 22 hours left to enroll

752 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