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
|
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Menus, StdCtrls;
type
TForm1 = class(TForm)
PopupMenu1: TPopupMenu;
procedure FormCreate(Sender: TObject);
procedure PopupMenu1Popup(Sender: TObject);
private
{ Déclarations privées }
public
{ Déclarations publiques }
end;
var
Form1: TForm1;
NewItem: TMenuItem;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
var
i: byte;
begin
for i := 1 to 4 do begin // création des 4 menus
NewItem := TMenuItem.create(self);
NewItem.caption := 'M ' + IntToStr(i);
NewItem.name := 'M' + IntToStr(i); // nom du menu
PopupMenu1.Items.Add(NewItem);
end;
end;
procedure TForm1.PopupMenu1Popup(Sender: TObject);
var
i: integer;
begin
for i := 0 to ComponentCount - 1 do
if Components[i] is TMenuItem then
if TMenuItem(components[i]).Name = 'M2' then
TMenuItem(components[i]).Enabled := false;
end;
end. |
Partager