In case someone else needs it, here is the code from Peter Below (TeamB):

procedure TForm1.Button1Click(Sender: TObject);
begin
  PopulateTreeViewWithActions;
end;

function ActionsSortByCatAndName(Item1, Item2: Pointer): Integer;
begin
  Result :=
    AnsiCompareStr(TAction(Item1).Category,
      TAction(Item2).Category);
  if Result = 0 then
    Result :=
      AnsiCompareStr(TAction(Item1).Name,
        TAction(Item2).Name);
end;

procedure TForm1.PopulateTreeViewWithActions;
var
  List: TList;

  procedure CollectActions;
  var
    I: Integer;
  begin
    for I := 0 to ComponentCount-1 do
      if Components[I] is TAction then
        List.Add(Components[I]);
  end; { CollectActions }

  procedure SortActions;
  begin
    List.Sort(ActionsSortByCatAndName);
  end; { SortActions }

  procedure ListActions;
  var
    LastCategory : string;
    I: Integer;
    ParentNode: TTreenode;
    Action: TAction;

    function CategoryName(Action: TAction): string;
    begin
      Result := Action.Category;
      if Result = '' then
        Result := '<no category>';
    end; { CategoryName }

  begin { ListActions }
    Treeview1.Items.BeginUpdate;
    try
      Treeview1.Items.Clear;
      if List.Count = 0 then
        Exit;

      LastCategory := '@@@@';
      ParentNode := nil;
      for I:= 0 to List.Count-1 do begin
        Action := TAction(List[I]);
        if Action.Category <> LastCategory then begin
          ParentNode := Treeview1.Items.Add(nil, CategoryName(Action));
          LastCategory := Action.Category;
        end; { if }
        Treeview1.Items.AddChildObject(ParentNode,
          Action.Name, Action);
      end; { for }
      Treeview1.FullExpand;
      // FullExpand will scroll the treeview to the end, scroll it
      // back to the top.
      Treeview1.Items.GetFirstNode.MakeVisible;
    finally
      Treeview1.Items.EndUpdate;
    end; { finally }
  end; { ListActions }

begin { PopulateTreeViewWithActions }
  List := TList.Create;
  try
    CollectActions;
    SortActions;
    ListActions;
  finally
    List.Free;
  end; { finally }
end; { PopulateTreeViewWithActions }




--- In [email protected], Rob Kennedy <[EMAIL PROTECTED]> wrote:
> jniaj wrote:
> > I need to populate a TreeView with nodes representing the action 
> > categories in my main form and subnodes representing the TActions
> > themselves. Can anyone help?
> 
> Sure. Which part do you need help with?
> 
> -- 
> Rob




-----------------------------------------------------
Home page: http://groups.yahoo.com/group/delphi-en/
To unsubscribe: [EMAIL PROTECTED] 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/delphi-en/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 


Reply via email to