Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Recursing Treeview nodes

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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

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…
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…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

609 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