unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, 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;implementationuses Unit2;{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject); begin form2.show; end;end.
procedure TForm1.Button1Click(Sender TObject); begin Form2.show(); end; 如果窗口2是动态生成: procedure TForm1.Button1Click(Sender TObject); var Form2:TForm; begin Form2:=TForm.Create(Application); end;
如果是模式的就用: form2.showmodal;
如果窗口2是动态生成: procedure TForm1.Button1Click(Sender TObject); var Form2:TForm; begin Form2:=TForm.Create(Application); Form2.show;(); end;
Windows, Messages, SysUtils, Variants, 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;implementationuses Unit2;{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
begin
form2.show;
end;end.
begin
Form2.show();
end;
如果窗口2是动态生成:
procedure TForm1.Button1Click(Sender TObject);
var
Form2:TForm;
begin
Form2:=TForm.Create(Application);
end;
procedure TForm1.Button1Click(Sender TObject);
var
Form2:TForm;
begin
Form2:=TForm.Create(Application);
Form2.show;();
end;
begin
FormTest := TFormTest.Create(Application);
try
FormTest.Showmodal;
finally
FormTest.Free;
end;
end;
1、form2.show;
2、form2.showModal;
如果是动态创建的:
1、无模式窗体:
procedure TForm1.Button1Click(Sender TObject);
var
Form2:TForm;
begin
Form2:=TForm.Create(Application);
Try
Form2.show;
except
form2.free;
end;
end;2、 procedure TForm1.Button1Click(Sender TObject);
var
Form2:TForm;
begin
Form2:=TForm.Create(Application);
Try
Form2.showmodal;
finally
form2.free;
end;
end;
注意如果是子窗体,改用release释放;而且释放时在destroy 中用这一个form2:=nil;
form2:=Tform2.create(nil);
form2.show;