if Form2=nil then 打开 else ...在Form2的 OnClose:Action:=caFree; OnDestory: Self:=nil;
打开时用showmodal就行了 别说重复的,不重复的都打不开了
if Form2=nil then 打开 else ...在Form2的 OnClose:Action:=caFree; OnDestory: Self:=nil;
if not Assigned(fmWorkOprt) then//打开OnClose:Action:=caFree; OnDestory: Self:=nil;
给你个通用的: /////////////////////通用子窗体开关 procedure OpenForm(FormClass: TFormClass; var AForm; AOwner:TComponent=nil); var i: 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 Child.WindowState:=wsNormal; Child.BringToFront; Child.Setfocus; TForm(AForm):=Child; exit; end; Child:=TForm(FormClass.NewInstance); TForm(AForm):=Child; if not assigned(aowner) then aowner:=application; Child.Create(AOwner); end;例如:OpenForm(TForm1,Form1); //创建 结束:Action:=CaFree //不变
//判断子窗体是否打开 pFormName表示子窗体名称 function IsExistsMdiChild(pFormName: string): integer; var i: integer; begin Result := -1; for i := 0 to Application.MainForm.MDIChildCount - 1 do begin if trim(Application.MainForm.MDIChildren[i].Name) = trim(pFormName) then Result := i; end; end;
else ...在Form2的
OnClose:Action:=caFree;
OnDestory: Self:=nil;
别说重复的,不重复的都打不开了
else ...在Form2的
OnClose:Action:=caFree;
OnDestory: Self:=nil;
OnDestory: Self:=nil;
/////////////////////通用子窗体开关
procedure OpenForm(FormClass: TFormClass; var AForm;
AOwner:TComponent=nil);
var
i: 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
Child.WindowState:=wsNormal;
Child.BringToFront;
Child.Setfocus;
TForm(AForm):=Child;
exit;
end;
Child:=TForm(FormClass.NewInstance);
TForm(AForm):=Child;
if not assigned(aowner) then aowner:=application;
Child.Create(AOwner);
end;例如:OpenForm(TForm1,Form1); //创建
结束:Action:=CaFree //不变
function IsExistsMdiChild(pFormName: string): integer;
var
i: integer;
begin
Result := -1;
for i := 0 to Application.MainForm.MDIChildCount - 1 do
begin
if trim(Application.MainForm.MDIChildren[i].Name) = trim(pFormName) then
Result := i;
end;
end;