Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Freeing TListView.data

Status
Not open for further replies.

OmniCog

Programmer
Jan 23, 2004
27
CA
I am trying to extend the TTreeView class.

How do I ensure that the memory of the object (it will always be an object) that is assigned to TreeNode.data is freed whenever a node is deleted in statements such as TV.Items.Clear?

I understand something like:
TNodeData(TV.Selected.Data).Free;
TV.Selected.Delete;

wil do but what if CustomTV.Items.clear is called or when the application is terminated? I can't even override TTreeCustomView.Clear or TTNode.Delete methods.

Any help is appreciated

David
 
indeed, expanding the TTreeView component to accomplish this task is not as easy as it would seem.
I would add a TObjectList somewhere and add the objects from the Treeview to the objectlist also.

Like this

Code:
uses contnrs,...
...
var MyObjects : TObjectList
// somewhere in init code
 MyObjects:=TObjectList.Create(True);

// create object , here is some psuedocode
 NodeData:=TNodeData.Create;
// add object to objectlist
 MyObjects.Add(NodeData);
// set treenode pointer towards our object 
 TreeNode.Data:=NodeData;

// object deletion, deleting the object from the TobjectList will free the object
MyObjects.Delete(MyObjects.IndexOf(TV.Selected.Data));
// delete Treeview node
TV.Selected.Delete;

cheers,
Daddy

-----------------------------------------------------
What You See Is What You Get
Never underestimate tha powah of tha google!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top