Children Property

TeeTree VCL for Borland Delphi and C++ Builder.
Post Reply
StoneAge
Newbie
Newbie
Posts: 6
Joined: Tue Nov 01, 2005 5:00 am

Children Property

Post by StoneAge » Mon Feb 27, 2012 5:42 pm

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,

Yeray
Site Admin
Site Admin
Posts: 9613
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Children Property

Post by Yeray » Thu Mar 01, 2012 4:38 pm

Hi,
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.
Childs is obsolete and just maintained for backwards compatibility. Use Children instead.
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.
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:

Code: Select all

  Tree1[0].AddConnection(Tree1[1]);
  if Tree1[0].AddConnection(Tree1[1]) <> nil then
    Tree1[0].Children.Add(Tree1[1]);
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)".
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:

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;
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.
Have you tried removing the child from the children list? Since you added it manually, you probably should remove it manually too.
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,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Post Reply