unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
{ANWENDUNG UND DLL}
IMachWas =
interface
procedure SetOnChange(value: TNotifyEvent);
function GetOnChange:TNotifyEvent;
procedure MachWas;
property OnChange:TNotifyEvent
read GetOnChange
write SetOnChange;
end;
{DLL}
TMachwas =
class(TInterfacedObject,IMachWas)
private
FOnChange:TNotifyEvent;
protected
public
procedure MachWas;
procedure SetOnChange(value: TNotifyEvent);
function GetOnChange:TNotifyEvent;
property OnChange:TNotifyEvent
read GetOnChange
write SetOnChange;
end;
{ANWENDUNG}
type
TForm1 =
class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private-Deklarationen }
FMachWas: IMachWas;
protected
procedure ReagiereAufMachwas(Sender: TObject);
public
{ Public-Deklarationen }
constructor Create(AOwner: TComponent);
override;
end;
//hier wird dann, wenn vorhanden, die Funktion der DLL geladen:
// function CreateTMachWas: TMachwas; external 'DieDLL.dll'
// Da ich aber jetzt zu faul bin die DLL zu erzeugen steht es hier ohne dem EXTERNAL
function CreateTMachWas: TMachwas;
var
Form1: TForm1;
implementation
{$R *.dfm}
{ ANWENDUNG }
procedure TForm1.Button1Click(Sender: TObject);
begin
FMachWas.MachWas;
end;
constructor TForm1.Create(AOwner: TComponent);
begin
inherited;
FMachWas := CreateTMachWas;
FMachWas.OnChange := ReagiereAufMachwas;
end;
procedure TForm1.ReagiereAufMachwas(Sender: TObject);
begin
ShowMessage('
REAKTION!');
end;
{ DLL }
function TMachwas.GetOnChange: TNotifyEvent;
begin
Result := FOnChange;
end;
procedure TMachwas.MachWas;
begin
if Assigned(FOnChange)
then
FOnChange(Self);
end;
procedure TMachwas.SetOnChange(value: TNotifyEvent);
begin
FOnChange := value;
end;
function CreateTMachWas: TMachwas;
begin
Result := TMachwas.Create;
end;
exports CreateTMachWas;
end.