Y
YL_YAN
Unregistered / Unconfirmed
GUEST, unregistred user!
主Pas文件引用从Pas文件,从Pas文件有一个输入参数过程,该过程靠主Form动态生成的Edit和Button完成(代码如下),如果动态生成的Button被点击,则把输入值返回unit2.pas中,赋值给实数 x ,这代码要怎样写? 谢谢!(100分)<br />主Pas文件引用从Pas文件,从Pas文件有一个输入参数过程,该过程靠主Form动态生成的Edit和Button完成(代码如下),如果动态生成的Button被点击,则把输入值返回unit2.pas中,赋值给实数 x ,这代码要怎样写? 谢谢!
主Pas文件代码如下:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls,UNIT2;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
s : String;
{ Private declarations }
public
property Inputvalue : String read s;
procedure Btn1Click(Sender: TObject);
{ Public declarations }
end;
var
Form1 :TForm1;
Edit1 :TEdit; //动态生成
ButtonA :TButton; //动态生成的Button按钮
Btn1ClickBool : Boolean; //判断动态生成的Button按钮是否被点击
implementation
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
var
x : real;
begin
read_r; //动态生成Edit、Button按钮来输入参数
等动态生成的Button被点击,如果被点击则把输入值返回unit2.pas中,赋值给实数x,这代码要怎样写?
read_real(x);
Form1.Caption :=FloattoStr(x);
end;
procedure TForm1.Btn1Click(Sender: TObject);
begin
S:=Edit1.Text;
Edit1.Visible:=False;
ButtonA.Visible :=False;
Btn1ClickBool :=True;
end;
end.
从Pas文件代码如下:
unit unit2;
interface
uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
procedure read_r;
procedure read_real(var x:real);
implementation
uses unit1;
procedure read_r;
begin
Edit1 :=TEdit.Create(Form1);
Edit1.Parent :=Form1;
Edit1.top :=10;
Edit1.left:=200;
ButtonA:=TButton.Create(Form1);
ButtonA.Parent :=Form1;
ButtonA.Left:=300;
ButtonA.top:=10;
ButtonA.OnClick:= Form1.Btn1Click;
end;
procedure read_real(var x:real);
begin
if Btn1ClickBool then x:=StrToFloat(Form1.Inputvalue);
end;
end.
主Pas文件代码如下:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls,UNIT2;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
s : String;
{ Private declarations }
public
property Inputvalue : String read s;
procedure Btn1Click(Sender: TObject);
{ Public declarations }
end;
var
Form1 :TForm1;
Edit1 :TEdit; //动态生成
ButtonA :TButton; //动态生成的Button按钮
Btn1ClickBool : Boolean; //判断动态生成的Button按钮是否被点击
implementation
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
var
x : real;
begin
read_r; //动态生成Edit、Button按钮来输入参数
等动态生成的Button被点击,如果被点击则把输入值返回unit2.pas中,赋值给实数x,这代码要怎样写?
read_real(x);
Form1.Caption :=FloattoStr(x);
end;
procedure TForm1.Btn1Click(Sender: TObject);
begin
S:=Edit1.Text;
Edit1.Visible:=False;
ButtonA.Visible :=False;
Btn1ClickBool :=True;
end;
end.
从Pas文件代码如下:
unit unit2;
interface
uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
procedure read_r;
procedure read_real(var x:real);
implementation
uses unit1;
procedure read_r;
begin
Edit1 :=TEdit.Create(Form1);
Edit1.Parent :=Form1;
Edit1.top :=10;
Edit1.left:=200;
ButtonA:=TButton.Create(Form1);
ButtonA.Parent :=Form1;
ButtonA.Left:=300;
ButtonA.top:=10;
ButtonA.OnClick:= Form1.Btn1Click;
end;
procedure read_real(var x:real);
begin
if Btn1ClickBool then x:=StrToFloat(Form1.Inputvalue);
end;
end.