unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TBeispiel=Procedure(Sender:TObject)
of object;
TMyClass=Class(TButton)
Private
FMethode:TBeispiel;
public
Constructor Create(AOwner:TComponent;Methode:TBeispiel);
End;
TForm1 =
class(TForm)
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
{ TMyClass }
constructor TMyClass.Create(AOwner: TComponent; Methode: TBeispiel);
begin
inherited Create(AOwner);
FMethode := Methode;
//TEST
Tag := 100;
if Assigned(FMethode)
then FMethode(Self);
//ENDE TEST
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Showmessage(IntToStr(TComponent(Sender).Tag));
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
With TMyClass.Create(Self,Button1Click)
do
begin
Parent := self;
Caption := '
Neuer Button';
end;
end;
end.