if assigned(Child01) then showmessage('已经创建') else Application.CreateForm(TChild01,Child01);注意在Child01的OnClose中写: Action:=caFree; Child01:=nil;procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean); begin if MessageDlg('确定要关闭吗?',mtConfirmation,[mbYes,mbNo],0)=mrYes then CanClose:=true else CanClose:=false; end;
如果不是dll mdichildform 可以以如下方式创建: procedure createchildform; var i:integer; begin with application.mainform do begin //扫描当前是否有欲创建的窗体存在,如果有将其置前,否则创建 for i := 0 to mdichildcount - 1 do if mdichildren[i].classname = _will_create_child_form.classname then begin mdichildren[i].bringtofront; exit; end; _will_create_child_form := T_will_create_child_form.create(application); end; end;
else Application.CreateForm(TChild01,Child01);注意在Child01的OnClose中写:
Action:=caFree;
Child01:=nil;procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
if MessageDlg('确定要关闭吗?',mtConfirmation,[mbYes,mbNo],0)=mrYes then
CanClose:=true
else CanClose:=false;
end;
procedure createchildform;
var
i:integer;
begin
with application.mainform do
begin
//扫描当前是否有欲创建的窗体存在,如果有将其置前,否则创建
for i := 0 to mdichildcount - 1 do
if mdichildren[i].classname = _will_create_child_form.classname then
begin
mdichildren[i].bringtofront;
exit;
end;
_will_create_child_form := T_will_create_child_form.create(application);
end;
end;