C
ccf
Unregistered / Unconfirmed
GUEST, unregistred user!
在运行时建立一个窗体后,访问该窗体时报错。主要是不知如何访问新建窗体,与之交换
数据,还有“Create(Aowner:TComponent)“中的Aowner如何使用。例如:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
Edit1: TEdit;
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);//用于建立一个新窗口。
procedure Button2Click(Sender: TObject);//用于在这个新窗口显示一个字符串
procedure show(s:string);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses
unit2;
{$R *.DFM}
procedure tform1.show(s:string);
begin
form1.edit1.text:=s;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
form2:tform2;
begin
form2:=tform2.create(self);
form2.Show;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
form2.display(edit1.text);
end;
end.
******************************
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm2 = class(TForm)
Edit1: TEdit;
procedure display(s:string);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form2: TForm2;
implementation
uses
unit1;
{$R *.DFM}
procedure tform2.display(s:string);
begin
form2.edit1.text:=s;
end;
end.
*******************************
数据,还有“Create(Aowner:TComponent)“中的Aowner如何使用。例如:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
Edit1: TEdit;
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);//用于建立一个新窗口。
procedure Button2Click(Sender: TObject);//用于在这个新窗口显示一个字符串
procedure show(s:string);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses
unit2;
{$R *.DFM}
procedure tform1.show(s:string);
begin
form1.edit1.text:=s;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
form2:tform2;
begin
form2:=tform2.create(self);
form2.Show;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
form2.display(edit1.text);
end;
end.
******************************
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm2 = class(TForm)
Edit1: TEdit;
procedure display(s:string);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form2: TForm2;
implementation
uses
unit1;
{$R *.DFM}
procedure tform2.display(s:string);
begin
form2.edit1.text:=s;
end;
end.
*******************************