unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 =
class(TForm)
Button1: TButton;
Button2: TButton;
Button3: TButton;
procedure Button1Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
FMyFunction : TNotifyEvent;
procedure MyFunction( Sender: TObject );
public
{ Public declarations }
procedure CallFunction( Func: TNotifyEvent );
end;
var
Form1: TForm1;
implementation
uses Unit2;
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
FMyFunction := MyFunction;
end;
procedure TForm1.CallFunction( Func: TNotifyEvent );
begin
MyFunction( Self );
if Assigned( Func )
and (@Func <> MethodAddress( '
MyFunction' ))
then
Func(
nil );
end;
procedure TForm1.MyFunction( Sender: TObject );
begin
Caption := '
MyFunction ' +
Name;
Sleep( 500 );
Caption := '
';
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
CallFunction(
nil );
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
Form2.CallFunction( FMyFunction );
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
if Not Form2.Visible
then
Form2.Show;
end;
end.
//**********************************************************
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm2 =
class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
FMyFunction : TNotifyEvent;
{ Private declarations }
procedure MyFunction( Sender: TObject );
public
{ Public declarations }
procedure CallFunction( Func: TNotifyEvent );
end;
var
Form2: TForm2;
implementation
uses Unit1;
{$R *.dfm}
procedure TForm2.FormCreate(Sender: TObject);
begin
FMyFunction := MyFunction;
end;
procedure TForm2.CallFunction( Func: TNotifyEvent );
begin
MyFunction( Self );
if Assigned( Func )
and (@Func <> MethodAddress( '
MyFunction' ))
then
Func(
nil );
end;
procedure TForm2.MyFunction( Sender: TObject );
begin
Caption := '
Function ' +
Name;
Sleep( 500 );
Caption := '
';
end;
procedure TForm2.Button1Click(Sender: TObject);
begin
Form1.CallFunction( FMyFunction );
end;
end.