这个函数可以动态建立窗体
procedure Tfmain.ShowForm(FormClass: TFormClass);
begin With FormClass.Create(self) do
try
ShowModal;
// showmessage(name);
finally
Free;
end;
end;ShowForm(Tfsz);
fsz为窗体名,Tfsz是他的定义
procedure Tfmain.ShowForm(FormClass: TFormClass);
begin With FormClass.Create(self) do
try
ShowModal;
// showmessage(name);
finally
Free;
end;
end;ShowForm(Tfsz);
fsz为窗体名,Tfsz是他的定义
var
Form2:TForm2;
begin
Form2:=TForm2.Create(Form1);
Form2.ShowModal();
delete Form2;
end;
接下来可以设置它的属性及事件了
Form1:=TForm1.Create(Form1);
Form1.Show
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;
i:integer;
implementation{$R *.DFM}procedure TForm1.Button1Click(Sender: TObject);
var
a:tform;
begin
a:=tform1.create(self);
a.show;
a.caption:=inttostr(i+1);
inc(i);
end;end.
to unsigned
procedure TForm1::Button1Click(Sender: TObject);
var
Form2:TForm2;
begin
Form2:=TForm2.Create(Form1);
Form2.ShowModal();
delete Form2;你的这句话看上去很有趣,可是调试不过呀
end;
form1.show;
在关闭时要记着用free销毁
var
NewForm:Tform;
begin
NewForm:=Tform.Create(application);
NewForm.Show;
end;
var
frm: TForm2;
begin
frm:=TForm2.Create(Self);
//或者如下:
//frm:=TForm2.Create(nil);
frm.ShowModal;
frm.Free;
end;
var
aForm:tform;
begin
if not assigned(aForm) then
try
aForm:=tform1.create(self);
aForm.showmodel;
finally
FreeAndNil(aForm);
end;
end;还要记住将aForm从Auto-create中去掉。