rudy999 2 Posted October 18, 2022 (edited) I do not use the ttreeview alot. I recently started to use it and while the application was in DEBUG mode there were no issues. No changes or ifdefs in code but simply changing to release - and it does not work! Delphi 11.2 with latest patches. example code snippet: calling: TfrmMain.ttreeViewChange(Sender: TObject; Node: TTreeNode); //.... if Node.HasAsParent(myParentNode) then begin myParentNode := Node.Parent; strParentText := myParentNode.Text; end; when in DEBUG = strParentText string has a value (which I use to compare and branch later in the code) when in RELEASE = strParentText is empty... Has anyone seen this before? I am do more tests and my plan is to make a dedicated pre populated treeview to test against. (and send to Embarcadero) Thanks in advance Edited October 19, 2022 by Sherlock Please use source tags Share this post Link to post
Paul TOTH 2 Posted October 19, 2022 I guess you means if Assigned(Node.Parent) then begin myParentNode := Node.Parent; strParentText := myParentNode.Text; end; Share this post Link to post
Sherlock 663 Posted October 19, 2022 8 hours ago, rudy999 said: TfrmMain.ttreeViewChange(Sender: TObject; Node: TTreeNode); //.... if Node.HasAsParent(myParentNode) then begin myParentNode := Node.Parent; strParentText := myParentNode.Text; end; The question is, what happens to myParentNode before the if statement. How is it initialized/filled? Share this post Link to post
rudy999 2 Posted October 19, 2022 Thank you for your responses, I changed my code to the following and it works: no need for a 'myParentNode' if Node.Level > 0 then begin strParentText := Node.Parent.Text; end; regards all Share this post Link to post
Remy Lebeau 1394 Posted October 19, 2022 4 hours ago, rudy999 said: I changed my code to the following and it works: no need for a 'myParentNode' Both TTreeNode.Level and TTreeNode.HasAsParent() are recursive, they walk the entire TTreeNode.Parent chain until the root of the tree is reached, or in the case of HasAsParent(), until the specified node is reached. You don't really need that recursiveness in your situation. Paul's solution is more efficient and will suit your situation just fine: if Assigned(Node.Parent) then // or: if Node.Parent <> nil then begin strParentText := Node.Parent.Text; end; Alternatively, to eliminate a redundant function call: var myParentNode: TTreeNode := Node.Parent; if Assigned(myParentNode) then // or: if myParentNode <> nil then begin strParentText := myParentNode.Text; end; Share this post Link to post