1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
|
type
TForm1 = class(TForm)
Button1: TButton;
ComboBox1: TComboBox;
Matriel1: TMainMenu; // si j'ai bien compris ton cas ...
procedure Button1Click(Sender: TObject);
procedure OnMenuItemClick(Sender: TObject);
private
...
implementation
uses inifiles;
...
procedure Tform1.OnMenuItemClick(Sender: TObject);
var mnu : TMenuitem;
begin // exemple : affectation même gestionnaire à tous menuitems...
mnu := sender as TMenuitem;
showmessage('Menu cliqué = '+ mnu.caption);
end;
procedure TForm1.Button1Click(Sender: TObject);
var
config: Tinifile;
NewItem, ParentMenu : TmenuItem;
x: Integer;
begin
Config := TIniFile.Create('sport.ini');
Config.ReadSections(combobox1.items);
Config.free;
// si on veut les items dans un menu de base 'fichier' ...
if Matriel1.Items.Count = 0 then
begin
ParentMenu := TMenuItem.Create(self);
ParentMenu.Name := 'MnuFichier';
ParentMenu.Caption := 'Fichier';
Matriel1.Items.Add(ParentMenu);
end;
for x := 0 to combobox1.items.count -1 do
begin
NewItem:=Tmenuitem.create(self);
NewItem.Caption := combobox1.Items[x];
NewItem.OnClick := OnMenuItemClick;
NewItem.Tag := x; // utile quelquefois
Newitem.Name := 'SousMenu'+inttostr(x);
// Matriel1.Items.add(NewItem); <--- si plusieurs menus de base
ParentMenu.Add(NewItem); // <--- ou si tous dans 1 menu 'fichier'
end;
end; |