Ich denke vom Grundprinzip her, hab ich es verstanden, oder?
Unit1
Code:
type
TForm1 = class(TForm)
Button1: TButton;
Memo1: TMemo;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private-Deklarationen }
MyObject: TMyClass;
procedure MyEventHandler(z: Integer);
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
{ TForm1 }
procedure TForm1.Button1Click(Sender: TObject);
begin
MyObject.Addition;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
MyObject := TMyClass.Create;
MyObject.OnMyEvent := MyEventHandler;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
MyObject.Free;
end;
procedure TForm1.MyEventHandler(z: Integer);
begin
Memo1.Lines.Add(IntToStr(z));
end;
end.
Unit2
Code:
type
TMyEvent = procedure (z: Integer) of Object;
TMyClass = class
private
FOnMyEvent: TMyEvent;
public
property OnMyEvent: TMyEvent read FOnMyEvent write FOnMyEvent;
procedure Addition;
end;
implementation
uses
Notify;
{ TMyClass }
procedure TMyClass.Addition;
var i,j,z: Integer;
begin
i := 4;
j := 3;
z := j + i;
if Assigned(FOnMyEvent) then
FOnMyEvent(z);
end;
end.