Hi

I am trying to create at treeview that contains a list of all components on
a form, grouped by the type of component (ClassName), with the Name of the
appropriate component listed as a child of the ClassName.
e.g form contains: Label1, Label2, Panel1, Memo1, Memo2 etc.
Result I am after:

Form1
->TLabel
        ->Label1
        ->Label2
->TMemo
        ->Memo1
        ->Memo2
->TPanel
        ->Panel1

My problem is that I cannot get the flow right to create this structure.
It works okay until I get to the second ClassName that has more than one
component, eg Memo.
It only shows one of the components as a child of the ClassName TMemo and
places the other at the same level as another occurance of TMemo.

Can anyone see what I am doing wrong in the code below.

Cheers

Chris Wallis
[EMAIL PROTECTED]

procedure TForm1.AddComponents(PropertyForm: TForm);
var
  Node: TTreeNode;
  b,I:Integer;
  Temp: TComponent;
begin
  {Does a root node already exist?}
  if (TreeViewCompts.Items.Count = 0) then
    begin
      {Add the root node}
      TreeViewCompts.Items.Clear; {remove any existing nodes}
      Node := TreeViewCompts.Items.Add(TreeViewCompts.Selected,Name); {Add
the root node}
    end;
  begin
  {Add a child node to the node just added}
    with TreeViewCompts.Items do
      begin
        for I := ComponentCount - 1 downto 0 do
            begin
                Temp := Components[I];
                for b := 0 to TreeViewCompts.Items.Count-1 do
                if TreeViewCompts.Items[b].Text = Temp.ClassName then
                TreeViewCompts.Items.AddChild(TreeViewCompts.Items[b],Temp.Name);
                AddChild(Node,Temp.ClassName);
            end;
        end;
  end;
end;

---------------------------------------------------------------------------
    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