1.窗口如何返回值?

ra3 2003-10-17 12:38:59
Form1 窗口调用 Form2 窗口, 如何让 Form2 窗口返回一个值给 Form1 ?
...全文
112 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhoutian618 2003-10-17
  • 打赏
  • 举报
回复
type
Tform1 = class(TForm);
end;

TForm2 = class(TForm);
public
vcID: string;
end;

im...
procedure TForm1.Button1Click(Sender: TObject);
begin
with TForm2.Create(Application) do
try
ShowModal;
ShowMessage(vcID);
finally
Free;
end;
end;
huojiehai 2003-10-17
  • 打赏
  • 举报
回复
.....
private
public
procedure ReturnValue;
..........


procedure TMyDialogBox.ReturnValue;
begin
Result := '返回值';
end;
procedure TMyDialogBox.OKButtonClick(Sender: TObject);

begin
ModalResult := mrOK;
end;

procedure TMyDialogBox.CancelButtonClick(Sender: TObject);
begin
ModalResult := mrCancel;

end;


procedure TForm1.Button1Click(Sender: TObject);

begin
if MyDialogBox1.ShowModal = mrOK then
begin
showmessage(MyDialogBox1.ReturnValue)
Beep;
end;
end;
佣工7001 2003-10-17
  • 打赏
  • 举报
回复
补充一下,设置的就是showmodal()的返回值,不过只能是整形的
佣工7001 2003-10-17
  • 打赏
  • 举报
回复
要有返回值,一定是showmodal,可以用modualresult
yanlls 2003-10-17
  • 打赏
  • 举报
回复
form2中设定一个变量不就行了吗?
ysycrazy 2003-10-17
  • 打赏
  • 举报
回复
//form1窗口
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;

type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

uses Unit2;

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
begin
if not assigned(form2) then
form2:=tform2.create(Application);
try
if form2.ShowModal= mrok then //如果form2返回mrok 则 OK!
ShowMessage('OK!');
finally
form2.free;
form2:=nil;
end;
end;

end.
//form2窗口
unit Unit2;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;

type
TForm2 = class(TForm)
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form2: TForm2;

implementation

{$R *.DFM}

procedure TForm2.FormClose(Sender: TObject; var Action: TCloseAction);
begin
ModalResult:=mrok;
end;

end.
xdxycx 2003-10-17
  • 打赏
  • 举报
回复
在窗口中建一个变量,用一个函数显示窗口,不就可以了吗
liyangyao970 2003-10-17
  • 打赏
  • 举报
回复
定义一个全局变量
在别的窗口引用~~~~
47522341 2003-10-17
  • 打赏
  • 举报
回复
如果是在同一个工程下就用传变量的方式吧;要简便些;
delphiseabird 2003-10-17
  • 打赏
  • 举报
回复
showmodal时候返回值还有点用
delphiseabird 2003-10-17
  • 打赏
  • 举报
回复
传变量吧,不费事
zzh54zzh 2003-10-17
  • 打赏
  • 举报
回复
showmodal。 modualresult
hiflower 2003-10-17
  • 打赏
  • 举报
回复
用 ShowModal 即可
如果不用 ShowModal,则也就无所谓返回值了

5,379

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧