Jump to content

Does TUniTreeNodes.Clear also free TUniTreeNode.Data objects ?


Jean-Marc Kiener

Recommended Posts

Is this correct?

procedure TDirectoryTree.ClearNodes;
var
  Index: integer;
begin

  for Index := 0  to FTreeView.Items.Count -1 do begin
    FreeAndNil(TNodedata( FtreeView.Items[ Index ].Data ) );
  end;
  FTreeView.Items.Clear;

end;

Or would al simple:
 

procedure TDirectoryTree.ClearNodes;
begin
  FTreeView.Items.Clear;
end;

be enough?

Link to comment
Share on other sites

4 hours ago, Jean-Marc Kiener said:

Is this correct?

Hello,

"You need to free only if you're the one who created the objects behind the data. What you create, you need to make sure is free'd. What the system creates the system will free. The Data properties have no concept of what you're putting in them, they're just pointers."

  • Thanks 1
Link to comment
Share on other sites

Probably, this code should work:

  for Index := 0  to FTreeView.Items.Count -1 do
    FreeAndNil(TNodedata( FtreeView.Items[ Index ].Data ) );
  FTreeView := nil;

You surely defined TNodedata, and created each assigned Data, so that it is your responsibility to release them.

FTreeView is of type TUniTreeNode, which implements an interface. It should be enough to assign nil to it to trigger its Destroy method.

  • Upvote 1
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...