procedure GetMenuName(MainMenu: TMainMenu; MenuItem: TMenuItem; StrList: TStringList); var Item: TMenuItem; Count, I: Integer; begin if MenuItem = nil then begin Count := MainMenu.Items.Count; if Count = 0 then exit; for I := 0 to Count - 1 do begin Item := MainMenu.Items[I]; StrList.Add(Item.Caption); if Item.Count > 0 then GetMenuName(MainMenu, Item, StrList); end; end else begin Count := MenuItem.Count; if Count = 0 then exit; for I := 0 to Count - 1 do begin Item := MenuItem.Items[I]; StrList.Add(Item.Caption); if Item.Count > 0 then GetMenuName(MainMenu, Item, StrList); end; end end;procedure TForm1.Button1Click(Sender: TObject); var StrList: TStringList; begin try StrList := TStringList.Create; StrList.Capacity := 256; GetMenuName(MainMenu1, nil, StrList); //... finally FreeAndNil(StrList); end; end;
var
Item: TMenuItem;
Count, I: Integer;
begin
if MenuItem = nil then
begin
Count := MainMenu.Items.Count;
if Count = 0 then exit;
for I := 0 to Count - 1 do
begin
Item := MainMenu.Items[I];
StrList.Add(Item.Caption);
if Item.Count > 0 then
GetMenuName(MainMenu, Item, StrList);
end;
end
else
begin
Count := MenuItem.Count;
if Count = 0 then exit;
for I := 0 to Count - 1 do
begin
Item := MenuItem.Items[I];
StrList.Add(Item.Caption);
if Item.Count > 0 then
GetMenuName(MainMenu, Item, StrList);
end;
end
end;procedure TForm1.Button1Click(Sender: TObject);
var
StrList: TStringList;
begin
try
StrList := TStringList.Create;
StrList.Capacity := 256; GetMenuName(MainMenu1, nil, StrList); //...
finally
FreeAndNil(StrList);
end;
end;