procedure TMainForm.ShowNowForm(F: TForm); var iCount: Integer; Found : Boolean; begin For iCount := 0 to MDIChildCount - 1 do begin if MDIChildren[iCount] <> F then MDIChildren[iCount].Close; end;
Found:=False; iCount:=0;
while ((Found = False) and (iCount < MDIChildCount)) do begin if MDIChildren[iCount] = F then Found := true else iCount := iCount+1; end;
if Found = false then begin F := TF.Create(self); //这个地方有问题,TF.Create(self);过不去; F.Show; end else begin F.Show; end;
end;
我直接用这段代码如下,没一点问题:
procedure TMainForm.N16Click(Sender: TObject); var iCount: Integer; Found : Boolean; begin For iCount := 0 to MDIChildCount - 1 do begin if MDIChildren[iCount] <> SetUserForm then MDIChildren[iCount].Close; end;
Found:=False; iCount:=0;
while ((Found = False) and (iCount < MDIChildCount)) do begin if MDIChildren[iCount] = SetUserForm then Found := true else iCount := iCount+1; end;
if Found = false then begin SetUserForm := TSetUserForm.Create(self); SetUserForm.Show; end else begin SetUserForm.Show; end; end;
----------------------------------------------
-
procedure TMainForm.ShowNowForm(F: TFormClass); var iCount: Integer; Found : Boolean; begin For iCount := 0 to MDIChildCount - 1 do begin if MDIChildren[iCount] <> F then MDIChildren[iCount].Close; end;
Found:=False; iCount:=0;
while ((Found = False) and (iCount < MDIChildCount)) do begin if MDIChildren[iCount] = F then Found := true else iCount := iCount+1; end;
if Found = false then begin F.classtype.create(self).show; end else begin F.Show; end;
各位高手,还是没搞定!! 没办法只有写成function了 function TMainForm.LookForNowForm(F: TForm): Boolean; var iCount : Integer; Found : Boolean; begin For iCount := 0 to MDIChildCount - 1 do begin if MDIChildren[iCount] <> F then MDIChildren[iCount].Close; end; Found := False; iCount := 0; while ((Found = False) and (iCount < MDIChildCount)) do begin if MDIChildren[iCount] = F then Found := true else iCount := iCount+1; end; Result := Found; end;
调用时:
procedure TMainForm.N16Click(Sender: TObject); begin if not LookForNowForm(SetUserForm) then begin SetUserForm := TSetUserForm.Create(self); SetUserForm.Show; end; end;