type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure FormDblClick(Sender: TObject);
procedure EigeneMethode(Sender: TObject); // <-------- vor "private"
private
procedure ExecuteMethod(Sender: TObject; Bezeichnung: string);
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.ExecuteMethod(Sender: TObject; Bezeichnung: string);
type
TExec = procedure(Sender: TObject) of object;
var
Methode: TMethod;
Exec: TExec;
begin
Methode.Code := MethodAddress(Bezeichnung);
Methode.Data := Self;
if Methode.Code <> nil then begin
Exec := TExec(Methode);
Exec(Sender);
end;
end;
procedure TForm1.FormDblClick(Sender: TObject);
begin
ShowMessage('Doppelt geklickt!');
end;
procedure TForm1.EigeneMethode(Sender: TObject);
begin
ShowMessage('Hello World!');
end;
// Aufrufe
procedure TForm1.Button1Click(Sender: TObject);
begin
ExecuteMethod(Sender, 'FormDblClick');
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
ExecuteMethod(Sender, 'EigeneMethode');
end;