0

Good day ...

I have a Treeview, which possess several children:

local ----- Son 0 ----- Son 1 ---------- Recipe 1 -------------------- Value1 ----------------------------- Olá1 ----------------------------- Olá2 ------------------------------------ Select Here -------------------- Value2 ---------- Revenue 2 ----- Son 2 ----- Son 3 

Say, I click the son (SELECT HERE), how do I get the first child of the root node (Son 1) ... I have some code that takes the Root, but I would like to take the child of that root that was clicked :

p: = Form4.TreeView1.Selected.Parent;            while Assigned (p.Parent) of the Begin                p: = p.Parent;            end; 
0

1 Answer 1

4

Just use an additional variable to keep track of "previous node", when you reach the root then the previous one is one you need? Ie

Prev := nil; p := Form4.TreeView1.Selected; if(p <> nil)then begin while Assigned(p.Parent) do begin Prev := p; p := p.Parent; end; end; // Prev, if assigned, should be the node you need 
Sign up to request clarification or add additional context in comments.

1 Comment

This code will crash if Selected or Selected.Parent is nil.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.