Jump to content

Deleting Nodes with Data and Children that also has Data and Children And So on from UniTreeView


elGringo

Recommended Posts

Lets say we have  tree connected to DB with simple id of record in Data, we cannot just delete the nodes, we should dispose pointers memory of Data of each Node.

 

It is known that unitreeview doesn't have all methods of treeview. For example we don't have GetNext method for easy traversing...

 

This way Ok only if all records loaded to UniTreeView. It is ok in my practice if tree has 100-200 nodes. If you need big tree it is better to load nodes on Expanding event dynamically.

 

Maybe someone wll need it. I do it like this

procedure DeleteNodeWithChildrenAndData(Node: TUniTreeNode);

var TreeView:TUniTreeView;
    i: Integer;
    TempNode:TUniTreeNode;
begin

TempNode:=Node;
TreeView:=MainForm.AdminFrame.GoodsFrame.TreeView;

   while Node.HasChildren do

              begin
                TempNode:=TreeView.Selected.GetLastChild;
                while TempNode.HasChildren do TempNode:=TempNode.GetLastChild;

                // do something here 
                Dispose(TempNode.Data);
                DeleteRecordFromDB(TempNode); //
                TreeView.Items.Delete(TempNode); //

              end;

      //Deleting initial Node
         DeleteRecordFromDB(Node);
         Dispose(Node.Data);
         TreeView.Items.Delete(Node);



end;
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...