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.
Getting the root text of a TreeNodeShape
Hi,
Instead of using the count property, make use of the fact that a Roots node parent is always nil.
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.Parent <> nil) then
begin
Ancestor := Shape.Parent;
Result := GetRootText(Ancestor);
end
else
Result := Shape.Text[0];
end;
Regards,
Tom.
Instead of using the count property, make use of the fact that a Roots node parent is always nil.
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.Parent <> nil) then
begin
Ancestor := Shape.Parent;
Result := GetRootText(Ancestor);
end
else
Result := Shape.Text[0];
end;
Regards,
Tom.