Y
YL_YAN
Unregistered / Unconfirmed
GUEST, unregistred user!
先从主Form上弹出一个从Form来输入实数,用来输入的从Form上的Edit控件是动态生成的(代码如下),接着把Edit上的输入的实数传回主Form(赋值给Label) ,运行时出错“Access violation at address 0000000E,read of address 0000000E', 这是为什么? 谢谢!
主Form的Pas文件如下:
unit Unit1;
interface
uses Math,Windows,SysUtils,CommDlg,CommCtrl,Penwin, WinTypes, WinProcs,
Messages, Classes, Graphics, Controls, Forms, Dialogs, Chart, Series,
ExtCtrls, Teengine, StdCtrls, Buttons,unit2;
type
TForm1 = class(TForm)
Image1: TImage;
Timer1: TTimer;
Label1: TLabel;
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.FormCreate(Sender: TObject);
begin
showmodal;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
RForm :TForm2;
Edit1 :TEdit;
begin
RForm:=TForm2.Create(Application);
Try
with RForm.Image1,Canvas do
begin
Textout(10,10,'Please input a real number:');
edit1:=tedit.Create(application);
edit1.Parent:=RForm;
edit1.Top:=10;
edit1.Left:=200;
s:=edit1.Text;
end;
with RForm do ShowModal;
finally RForm.Free;
end;
end;
end.
从Form的Pas文件如下:
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls, StdCtrls;
type
TForm2 = class(TForm)
Image1: TImage;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form2: TForm2;
implementation
uses Unit1;
{$R *.DFM}
procedure TForm2.Button1Click(Sender: TObject);
var
Edit1 :TEdit;
begin
Form1.Label1.Caption:=Edit1.Text;
close;
end;
end.
主Form的Pas文件如下:
unit Unit1;
interface
uses Math,Windows,SysUtils,CommDlg,CommCtrl,Penwin, WinTypes, WinProcs,
Messages, Classes, Graphics, Controls, Forms, Dialogs, Chart, Series,
ExtCtrls, Teengine, StdCtrls, Buttons,unit2;
type
TForm1 = class(TForm)
Image1: TImage;
Timer1: TTimer;
Label1: TLabel;
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.FormCreate(Sender: TObject);
begin
showmodal;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
RForm :TForm2;
Edit1 :TEdit;
begin
RForm:=TForm2.Create(Application);
Try
with RForm.Image1,Canvas do
begin
Textout(10,10,'Please input a real number:');
edit1:=tedit.Create(application);
edit1.Parent:=RForm;
edit1.Top:=10;
edit1.Left:=200;
s:=edit1.Text;
end;
with RForm do ShowModal;
finally RForm.Free;
end;
end;
end.
从Form的Pas文件如下:
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls, StdCtrls;
type
TForm2 = class(TForm)
Image1: TImage;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form2: TForm2;
implementation
uses Unit1;
{$R *.DFM}
procedure TForm2.Button1Click(Sender: TObject);
var
Edit1 :TEdit;
begin
Form1.Label1.Caption:=Edit1.Text;
close;
end;
end.