C
cnh
Unregistered / Unconfirmed
GUEST, unregistred user!
File>>New>>Application,Unit1(Form1),然后File>>New>>Form,Unit2(Form2)。
Unit1(Form1)是主单元,动态创建Form2( aa:= TForm2.Create( self ); )。现在要在Unit1里面得到其动态创建的实例aa的函数aerty的地址,并且调用这个函数,请问该怎么写,调试通过立刻给分,谢谢!
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, Unit2;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
aa: TForm2;
p: pointer;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
aa:= TForm2.Create( self );
aa.BorderStyle:= bsNone;
aa.WindowState:= wsMaximized;
aa.Position:= poScreenCenter;
aa.Visible:=true ;
aa.BringToFront ;
aa.Show ;
p:= @aa.aerty; // 我想得到实例aa的函数aerty的地址
aa.aerty; // 并且运行实例aa的函数aerty
end;
end.
下面是Unit2
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;
type
TForm2 = class(TForm)
Button1: TButton;
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form2: TForm2;
implementation
{$R *.dfm}
procedure TForm2.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Action := caFree;
end;
procedure TForm2.Button1Click(Sender: TObject);
begin
self.Close;
end;
procedure TForm2.aerty;
begin
showmessage('OK');
end;
end.
请问我在Unit2里面该怎样声明或处理函数aerty?谢谢!
Unit1(Form1)是主单元,动态创建Form2( aa:= TForm2.Create( self ); )。现在要在Unit1里面得到其动态创建的实例aa的函数aerty的地址,并且调用这个函数,请问该怎么写,调试通过立刻给分,谢谢!
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, Unit2;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
aa: TForm2;
p: pointer;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
aa:= TForm2.Create( self );
aa.BorderStyle:= bsNone;
aa.WindowState:= wsMaximized;
aa.Position:= poScreenCenter;
aa.Visible:=true ;
aa.BringToFront ;
aa.Show ;
p:= @aa.aerty; // 我想得到实例aa的函数aerty的地址
aa.aerty; // 并且运行实例aa的函数aerty
end;
end.
下面是Unit2
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;
type
TForm2 = class(TForm)
Button1: TButton;
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form2: TForm2;
implementation
{$R *.dfm}
procedure TForm2.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Action := caFree;
end;
procedure TForm2.Button1Click(Sender: TObject);
begin
self.Close;
end;
procedure TForm2.aerty;
begin
showmessage('OK');
end;
end.
请问我在Unit2里面该怎样声明或处理函数aerty?谢谢!