Getting the root text of a TreeNodeShape
Posted: Tue Jun 29, 2004 10:04 pm
I used the following code to get the root text of a TreeNodeShape:
function GetRootText(Shape: TTreeNodeShape): string;
// Extract the text of the root of the tree that Shape belongs to.
// Recurse back up the tree until there are no parents.
var
Ancestor: TTreeNodeShape;
begin
if Shape.Parents.Count > 0 then
begin
Ancestor := Shape.Parent;
Result := GetRootText(Ancestor);
end
else
Result := Shape.Text[0];
end;
With D5, TeeChart 5pro and TeeTree1.04 it worked fine. With TeeTree v 1.05 Shape.Parents.Count is always zero even when Shape.Parent is not nil.
(I know that in v2 TTreeNodeShape has the 'Root' property - but I'm working in v1!).
Is there a more reliable function to obtain the root text?
TIA.
function GetRootText(Shape: TTreeNodeShape): string;
// Extract the text of the root of the tree that Shape belongs to.
// Recurse back up the tree until there are no parents.
var
Ancestor: TTreeNodeShape;
begin
if Shape.Parents.Count > 0 then
begin
Ancestor := Shape.Parent;
Result := GetRootText(Ancestor);
end
else
Result := Shape.Text[0];
end;
With D5, TeeChart 5pro and TeeTree1.04 it worked fine. With TeeTree v 1.05 Shape.Parents.Count is always zero even when Shape.Parent is not nil.
(I know that in v2 TTreeNodeShape has the 'Root' property - but I'm working in v1!).
Is there a more reliable function to obtain the root text?
TIA.