2007. július 20., péntek

How to load a main menu into a TTreeView


Problem/Question/Abstract:

How to load a main menu into a TTreeView

Answer:

procedure AddToTree(Menu: TMenuItem; Tree: TTreeView; PNode: TTreeNode);
var
  x: Integer;
  Node: TTreeNode;
begin
  Node := Tree.Items.AddChild(PNode, Menu.Caption);
  if Menu.Count > 0 then
  begin
    for x := 0 to Menu.Count - 1 do
    begin
      AddToTree(Menu.Items[x], Tree, Node);
    end;
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  x: Integer;
begin
  TreeView1.Items.Clear;
  for x := 0 to MainMenu1.Items.Count - 1 do
  begin
    AddToTree(MainMenu1.Items[x], TreeView1, nil);
  end;
end;

Nincsenek megjegyzések:

Megjegyzés küldése