Всем большое спасибо! Вот так всё работает:
Код:
procedure Fill_MainMenu(MainMenu: TMainMenu; MenuItem: TMenuItem;
Directory: String);
var
SubMenuItem: TMenuItem;
SearchRec: TSearchRec;
begin
if FindFirst(Directory + '\' + '*.*', faDirectory, SearchRec) = 0 then
Repeat
if (SearchRec.Name <> '.') and (SearchRec.Name <> '..') and
((SearchRec.Attr and faDirectory) = faDirectory) then
begin
SubMenuItem := TMenuItem.Create(nil);
SubMenuItem.Caption := SearchRec.Name;
if MenuItem = nil Then
MainMenu.Items[0].Add(SubMenuItem)
else
MenuItem.Insert(0, SubMenuItem);
Fill_MainMenu(MainMenu, SubMenuItem,
Directory + SearchRec.Name + '\');
end;
Until FindNext(SearchRec) <> 0;
FindClose(SearchRec);
end;