Hello folks,
I'm trying to use TeeTree as a Flowchart manager, but, for some validation purposes, I need to know and use the Children property.
Some problems I experience and am still having trouble:
1 - TTreeNodeShape class has 2 misleading properties: Children and Childs. I've found no clue if both link to the same values or if one is preferable over another.
2 - The Parent property is updated automatically, but Childs/Children are not. When one inserts two nodes A and B in a TTree and creates a link from A to B, one can verify that A is in B.Parents list, but B is not in A.Children. In a global aspect, A.Children is always empty.
3 - I need to know information about the children of one node, and I'd rather not navigate through every connection to find out the children of one node. So I made some hardcode to manually insert the child in the Children list of a node. Whenever a new connection is made, lets say from A to B, I insert B manually in the Children list of A, using "A.Children.Add(B)".
4 - Now the big problem. When I try to delete a connected node, I get an "Invalid Pointer Operation" error. If I don't manually add nodes in the Children list, no problem is found. But if I insert the children, I get errors everytime I try to delete some node.
I suppose I'm doing something wrong in my logic, but can't seem to find the errors in it. I hope someone can help me and tell me if I'm using any wrong methods or an alternative, and hopefully easy, way of finding informations about children nodes (the navigate through connection solution is on my mind, but I'd rather not do it. It's quite ugly...)
I'm using Delphi XE and the latest version of TTree at the moment.
Kind regards,
Children Property
Re: Children Property
Hi,
I'm not getting any error with the example below, so I'm probably missing something relevant. However, I'm still obtaining a child when looping them.
Childs is obsolete and just maintained for backwards compatibility. Use Children instead.StoneAge wrote:1 - TTreeNodeShape class has 2 misleading properties: Children and Childs. I've found no clue if both link to the same values or if one is preferable over another.
Right. I've added it to the wish list to be implemented asap (TV52016061). In the meanwhile I'm afraid the only solution is to add the childs to the list manually. In example:StoneAge wrote:2 - The Parent property is updated automatically, but Childs/Children are not. When one inserts two nodes A and B in a TTree and creates a link from A to B, one can verify that A is in B.Parents list, but B is not in A.Children. In a global aspect, A.Children is always empty.
Code: Select all
Tree1[0].AddConnection(Tree1[1]);
if Tree1[0].AddConnection(Tree1[1]) <> nil then
Tree1[0].Children.Add(Tree1[1]);
Alternatively, you could loop into all the nodes parents list and add all the children instead of doing it each time you add a connection. Something like this:StoneAge wrote:3 - I need to know information about the children of one node, and I'd rather not navigate through every connection to find out the children of one node. So I made some hardcode to manually insert the child in the Children list of a node. Whenever a new connection is made, lets say from A to B, I insert B manually in the Children list of A, using "A.Children.Add(B)".
Code: Select all
for i:=0 to Tree1.Shapes.Count-1 do
begin
for j:=0 to Tree1[i].Parents.Count-1 do
begin
if Tree1[i].Parents[j].Children.IndexOf(Tree1[i]) = -1 then
Tree1[i].Parents[j].Children.Add(Tree1[i]);
end;
end;
Have you tried removing the child from the children list? Since you added it manually, you probably should remove it manually too.StoneAge wrote:4 - Now the big problem. When I try to delete a connected node, I get an "Invalid Pointer Operation" error. If I don't manually add nodes in the Children list, no problem is found. But if I insert the children, I get errors everytime I try to delete some node.
I'm not getting any error with the example below, so I'm probably missing something relevant. However, I'm still obtaining a child when looping them.
Code: Select all
procedure TForm1.FormCreate(Sender: TObject);
var i, j, z: Integer;
conn: TTreeConnection;
begin
Tree1.AddNewShape(TTreeNodeShape.Create(Self), 0, 0, 'Shape1', nil);
Tree1.AddNewShape(TTreeNodeShape.Create(Self), 0, 0, 'Shape2', nil);
conn:=Tree1[0].AddConnection(Tree1[1]);
{if conn <> nil then
Tree1[0].Children.Add(Tree1[1]);}
for i:=0 to Tree1.Shapes.Count-1 do
begin
for j:=0 to Tree1[i].Parents.Count-1 do
begin
if Tree1[i].Parents[j].Children.IndexOf(Tree1[i]) = -1 then
Tree1[i].Parents[j].Children.Add(Tree1[i]);
end;
end;
{for i:=0 to Tree1.Shapes.Count-1 do
begin
for j:=0 to Tree1[i].Children.Count-1 do
begin
if Tree1[i].Children[j] = Tree1[1] then
Tree1[i].Children.
end;
end;}
Tree1[1].Destroy;
for i:=0 to Tree1.Shapes.Count-1 do
begin
for j:=0 to Tree1[i].Parents.Count-1 do
ShowMessage(Tree1[i].Parents[j].SimpleText + ' is one of ' + Tree1[i].SimpleText + ' parents');
for j:=0 to Tree1[i].Children.Count-1 do
ShowMessage(Tree1[i].Children[j].SimpleText + ' is one of ' + Tree1[i].SimpleText + ' childen');
end;
end;
Best Regards,
Yeray Alonso Development & Support Steema Software Av. Montilivi 33, 17003 Girona, Catalonia (SP) | |
Please read our Bug Fixing Policy |