procedure TForm1.Button1Click(Sender: TObject);
const
a: array[0..5] of Integer = (-1, 1, -1, -1, 2, -1);
var
i: Integer;
RootItem, ChildItem: TMenuItem;
begin
RootItem:= Form1.Menu.Items[0]; // вариант 1
for i:= Low(a) to High(a) do
begin
ChildItem:= TMenuItem.Create(RootItem);
RootItem.Add(ChildItem);
ChildItem.Caption:= Format('Item %d', [i]);
ChildItem.ImageIndex:= a[i];
end;
RootItem:= TMenuItem.Create(Form1.Menu); // вариант 2
Form1.Menu.Items.Add(RootItem);
RootItem.Caption:= Format('Menu %d', [0]);
RootItem.ImageIndex:= a[0];
for i:= Low(a) to High(a) do
begin
ChildItem:= TMenuItem.Create(RootItem);
ChildItem.Name:= Format('miItem%d', [i]);
RootItem.Add(ChildItem);
ChildItem.Caption:= Format('Item %d', [i]);
ChildItem.ImageIndex:= a[i];
end;
end;