Delphi的模式窗体两种方式:
方式1、
procedure TForm1.Button1Click(Sender: TObject);
begin
Form2 := TForm2.Create(Application);
try
if Form2.ShowModal=mrok then
showmessage('ss');
{其它操作}
finally
Form2.Free;
Form2:=nil;
end;
end;
方式2、
procedure TForm1.Button1Click(Sender: TObject);
begin
Form2 := TForm2.Create(nil);
try
Form2.ShowModal;
finally
Form2.Free;
Form2:=nil;
end;
end;
非模式窗体
procedure TForm1.Button1Click(Sender: TObject);
begin
if not assigned(Form2) then
Form2 := TForm2.Create(Application);
Form2.show;
end;
注:如果非模式窗体的属主对是nil不是Application,也就
说如下
procedure TForm1.Button1Click(Sender: TObject);
begin
if not assigned(Form2) then
Form2 := TForm2.Create(nil);
Form2.show;
end;
那么这种窗体需要手工释放窗体内存:
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Action:=caFree;
end;
不仅是手工释放窗体内存,还要将窗体变量Form2的指针置为空:
procedure TForm2.FormDestroy(Sender: TObject);
begin
Form2:=nil;
end;
386

被折叠的 条评论
为什么被折叠?



