Jean-Marc Kiener Posted October 11, 2022 Share Posted October 11, 2022 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? Quote Link to comment Share on other sites More sharing options...
zilav Posted October 11, 2022 Share Posted October 11, 2022 39 minutes ago, Jean-Marc Kiener said: FreeAndNil(TNodedata( FtreeView.Items[ Index ].Data ) ); +1 1 Quote Link to comment Share on other sites More sharing options...
风吹小机机 Posted October 11, 2022 Share Posted October 11, 2022 That's it FTreeView.Items.Clear; Quote Link to comment Share on other sites More sharing options...
Sherzod Posted October 11, 2022 Share Posted October 11, 2022 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." 1 Quote Link to comment Share on other sites More sharing options...
davidizadar Posted October 12, 2022 Share Posted October 12, 2022 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. 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.