Delphi-Quellcode:
type
TForm1 = class(TForm)
RichEdit1: TRichEdit;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
popRTF: TPopupMenu;
procedure OnMenuItemClick(Sender: TObject);
public
{ Public declarations }
end;
var
Form1 : TForm1;
implementation
{$R *.dfm}
procedure TForm1.OnMenuItemClick(Sender: TObject);
begin
case TMenuItem(Sender).Tag of
0: ShowMessage(TMenuItem(Sender).Caption);
1: ShowMessage(TMenuItem(Sender).Caption);
2: ShowMessage(TMenuItem(Sender).Caption);
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
mi : TMenuItem;
begin
popRTF := TPopupMenu.Create(Form1);
mi := TMenuItem.Create(Form1);
mi.Caption := 'Item0';
mi.Tag := 0;
mi.OnClick := OnMenuItemClick;
popRtf.Items.Add(mi);
mi := TMenuItem.Create(Form1);
mi.Caption := 'Item1';
mi.Tag := 1;
mi.OnClick := OnMenuItemClick;
popRtf.Items.Add(mi);
mi := TMenuItem.Create(Form1);
mi.Caption := 'Item2';
mi.Tag := 2;
mi.OnClick := OnMenuItemClick;
popRtf.Items.Add(mi);
RichEdit1.PopupMenu := popRTF;
end;
Sollte selbst erklärend sein.