在A中的button中写:
with TFormB.Create(Application) do
try
if ShowModal = mrOk then
Self.StaticText1.Caption := edit1.Text;
finally
Free;
end;
with TFormB.Create(Application) do
try
if ShowModal = mrOk then
Self.StaticText1.Caption := edit1.Text;
finally
Free;
end;
begin
if not assigned(form2) then
begin
application.createform(form2,Tform2);
form2.showmodal;
end;
if form2.modalresult = mrok then
form1.StaticText1.Caption := form2.edit1.Text;
end;
interfaceuses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
Label1: TLabel;
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
form2.Show;
end;end.
Unit2.pas
unit Unit2;interfaceuses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls,Unit1;type
TForm2 = class(TForm)
Edit1: TEdit;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form2: TForm2;implementation{$R *.DFM}procedure TForm2.Button1Click(Sender: TObject);
var
h: THandle;
s: String;
begin
s:=Edit1.Text;
Form1.Label1.Caption :=s;
end;end.
如果我不要求对话框退出就有此效果,该如何做呢?即无mrok了...
只能把这段代码放在Form2的OnOk里才行,如何做?
A.Label1.Caption:=B.Edit1.Text;