Thanks Stephen and Kurt

I had just solved the looping problem before I received your e-mails this
morning.

I have taken a slightly different approach to your code Stephen and split
the process into two procedures, both listed below.  The problem was the
looping as you both had suggested.

The only real difference I can see is that my code places the first node
'Form1' at the root and then the ClassNames as children off that.

Thanks for your help

Chris

procedure TForm1.AddComponents(AForm: TForm);
var
  j: Integer;
  PropInfo: PPropInfo;
begin
  for j:=0 to ComponentCount-1 do
  begin
    PropInfo:=GetPropInfo(Components[j].classinfo,'Name');

AddComponentstoList(AForm,GetStrProp(Components[j],PropInfo),Components[j].C
lassName);
  end;
  TreeViewList.AlphaSort;
end;

procedure TForm1.AddComponentstoList (AForm: TForm; CompName: String;
ClassName: String);
var
  Found: Boolean;
  Node: TTreeNode;
begin
  if (TreeViewList.Items.Count = 0) then
        begin   {Add the root node}
        TreeViewList.Items.Clear; {remove any existing nodes}
          Node := TreeViewList.Items.Add(TreeViewList.Selected,Name); {Add the root
node}
  end;

  Node := TreeViewList.Items.GetFirstNode;
  while not found do
  begin
    if node = nil then
        begin
          Node :=
TreeViewList.Items.AddChild(TreeViewList.Items.GetFirstNode,ClassName);
          Node := TreeViewList.Items.AddChild(Node,CompName);
          found:=true;
        end
    else
        begin
          if Node.text=ClassName then
            begin       {Add child of ClassName}
                Node := TreeViewList.Items.AddChild(Node,CompName);
                exit;
            end
          else
           Node:=Node.GetNext;
        end
  end;
end;

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]On
Behalf Of Stephen Bertram
Sent: Monday, 12 March 2001 12:19 p.m.
To: Multiple recipients of list delphi
Subject: RE: [DUG]: Adding nodes to Treeview and dupicates


Chris

I imagine you've solved the problem by now.  Basically you had not
identified the correct Class node in your checking loop.

I came up with the following which I have checked :-)

procedure TForm1.AddComponents(PropertyForm: TForm);
var
  RootNode, ClassNode: TTreeNode;
  b,I:Integer;
  Temp: TComponent;
begin
  with TreeViewCompts.Items
  begin
//  Clear Existing Nodes
    TreeViewCompts.Items.Clear;
    RootNode := TreeViewCompts.Items.Add(NIL,Name); {Add the root node}

//  Sequence through all components
    for I := ComponentCount - 1 downto 0 do
    begin
      Temp := Components[I];

//    Check to see if class in tree
      ClassNode := NIL;
        for b := 0 to TreeViewCompts.Items.Count-1 do
      begin
        if TreeViewCompts.Items[b].Text = Temp.ClassName then
        begin
            ClassNode := TreeViewCompts.Items[b];
          Break;
        end;
      end;
      if ClassNode = NIL then
        ClassNode := AddChild(Node,Temp.ClassName);
      AddChild(ClassNode,Temp.Name);
    end;
  end;
end;

Cheers

Stephen
---------------------------------------------------------------------------
    New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
                  Website: http://www.delphi.org.nz
To UnSub, send email to: [EMAIL PROTECTED]
with body of "unsubscribe delphi"


---------------------------------------------------------------------------
    New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
                  Website: http://www.delphi.org.nz
To UnSub, send email to: [EMAIL PROTECTED] 
with body of "unsubscribe delphi"

Reply via email to