好象还不行 if not assigned(ZhuangJiRenYuanGuanLi)then ZhuangJiRenYuanGuanLi:=TZhuangJiRenYuanGuanLi.Create(self);我用上面的,ZhuangJiRenYuanGuanLi:=TZhuangJiRenYuanGuanLi.Create(self);这句没执行
不能用showmodal,用showmodal就没有这问题了
没执行是窗体已创建,你只需show一下了,前一句就是判断窗体是否已创建,没有创建再创建,然后显示 if not assigned(ZhuangJiRenYuanGuanLi)then ZhuangJiRenYuanGuanLi:=TZhuangJiRenYuanGuanLi.Create(self); ZhuangJiRenYuanGuanLi.show;如果已创建则直接显示;
在create时判断一下嘛: if not Assigned(aForm) then aForm:=TaForm.Create(Application);
给你个函数吧,判断MDI窗体的创建Procedure OpenForm(FormClass: TFormClass; var fm; AOwner:TComponent); var I,j: Integer; Child:TForm; begin for I := 0 to Screen.FormCount -1 do if Screen.Forms[I].ClassType=FormClass then begin Child:=Screen.Forms[I]; if Child.WindowState=wsMinimized then ShowWindow(Child.handle,SW_SHOWNORMAL) else ShowWindow(Child.handle,SW_SHOWNA); if (not Child.Visible) then Child.Visible:=True; Child.BringToFront; Child.Setfocus; TForm(fm):=Child; Exit; end; Child:=TForm(FormClass.NewInstance); TForm(fm):=Child; Child.Create(AOwner); child.show; end;
frm: TForm;
begin
if Assigned(frm) then
ShowMessage('窗体已经创建');
frm.ShowModal; 就保证你的窗体在最前面
frm.FormStyle := fsStayOnTop; 显示在最前面end;
用Assigned判断对象是否存在,用Assigned()可以判定任何对象,
showmodal模式窗体显示在最前
if not assigned(ZhuangJiRenYuanGuanLi)then
ZhuangJiRenYuanGuanLi:=TZhuangJiRenYuanGuanLi.Create(self);我用上面的,ZhuangJiRenYuanGuanLi:=TZhuangJiRenYuanGuanLi.Create(self);这句没执行
不能用showmodal,用showmodal就没有这问题了
if not assigned(ZhuangJiRenYuanGuanLi)then
ZhuangJiRenYuanGuanLi:=TZhuangJiRenYuanGuanLi.Create(self);
ZhuangJiRenYuanGuanLi.show;如果已创建则直接显示;
先定义一个全局的整型值: FormRef: Integer = 0;
然后,在你的窗体Create的时候 Inc(FormRef);
在窗体被Free的时候,Desc(FormRef);//注意:一定是Free,而不是Close,Close不一定是Free.
那么每次判断 FormRef > 0 就可以了 :)
Application.CreateForm(TZhuangJiRenYuanGuanLi,ZhuangJiRenYuanGuanLi);
去掉试一试。
if not Assigned(aForm) then
aForm:=TaForm.Create(Application);
var
I,j: Integer;
Child:TForm;
begin
for I := 0 to Screen.FormCount -1 do
if Screen.Forms[I].ClassType=FormClass then
begin
Child:=Screen.Forms[I];
if Child.WindowState=wsMinimized then
ShowWindow(Child.handle,SW_SHOWNORMAL)
else
ShowWindow(Child.handle,SW_SHOWNA);
if (not Child.Visible) then Child.Visible:=True;
Child.BringToFront;
Child.Setfocus;
TForm(fm):=Child;
Exit;
end;
Child:=TForm(FormClass.NewInstance);
TForm(fm):=Child;
Child.Create(AOwner);
child.show;
end;
.free
改为.release