一条大鱼,被你抓了把柄我,我收声。
楼主,写个例子给你(窗体间传递参数):
工程文件:
program ShowModalForm;
uses
Forms,
U_Main in 'U_Main.pas' {f_Main},
U_ModalForm in 'U_ModalForm.pas' {f_ModalForm};
{$R *.res}
begin
Application.Initialize;
Application.CreateForm(Tf_Main, f_Main);
Application.Run;
end.
---------------------------------------------------
主窗体:
unit U_Main;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
Tf_Main = class(TForm)
BtnMethodA: TButton;
Edit1: TEdit;
BtnMethodB: TButton;
btnMethodC: TButton;
procedure BtnMethodAClick(Sender: TObject);
procedure BtnMethodBClick(Sender: TObject);
procedure btnMethodCClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
f_Main: Tf_Main;
implementation
uses U_ModalForm;
{$R *.dfm}
procedure Tf_Main.BtnMethodAClick(Sender: TObject);
var
form:Tf_ModalForm;
begin
form:=Tf_ModalForm.Create(nil,Edit1.Text);
with form do
try
ShowModal;
if ModalResult=mrOK then
ShowMessage('答案是: '+edit2.Text);
finally
free;
end;
end;
procedure Tf_Main.BtnMethodBClick(Sender: TObject);
var
strAnswer:String;
begin
if ShowQuestionForm(Edit1.Text,strAnswer) then
ShowMessage('答案是: '+strAnswer);
end;
procedure Tf_Main.btnMethodCClick(Sender: TObject);
var
form:Tf_ModalForm;
begin
form:=Tf_ModalForm.Create(nil);
with form do
try
Edit1.Text:=self.Edit1.Text;
ShowModal;
if ModalResult=mrOK then
ShowMessage('答案是: '+edit2.Text);
finally
free;
end;
end;
end.
------------------------------------------------------
Modal窗体:
unit U_ModalForm;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons;
type
Tf_ModalForm = class(TForm)
Edit1: TEdit;
Edit2: TEdit;
BitBtn1: TBitBtn;
BitBtn2: TBitBtn;
btnGetQuestion: TButton;
procedure btnGetQuestionClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
FQuestion:String;
public
{ Public declarations }
constructor Create(AOwner:TComponent;AQuestion:String);overload;
end;
Function ShowQuestionForm(AQuesition:string;var Answer:String):Boolean;
implementation
{$R *.dfm}
Function ShowQuestionForm(AQuesition:string;var Answer:String):Boolean;
var
form:Tf_ModalForm;
begin
Result:=False;
form:=Tf_ModalForm.Create(nil);
with form do
try
Edit1.Text:=AQuesition;
ShowModal;
if ModalResult=mrOk then
begin
Answer:=edit2.text;
Result:=True;
end;
finally
free;
end;
end;
{ Tf_ModalForm }
constructor Tf_ModalForm.Create(AOwner: TComponent
AQuestion: String);
begin
inherited Create(AOwner);
FQuestion:=AQuestion;
end;
procedure Tf_ModalForm.btnGetQuestionClick(Sender: TObject);
begin
Edit1.Text:=FQuestion;
end;
procedure Tf_ModalForm.FormCreate(Sender: TObject);
begin
Caption:=DateTimeToStr(now);
end;
end.
我以前写的例子: http://downloads.2ccc.com/simples/forms/InheritedOverload.rar