if form1=nil then
form1 :=Tform1.Create(self);
form1.show ;

解决方案 »

  1.   

    是个自定义的方法,创建窗体用的:
    procedure Tfrmmain.ShowAddForm(FormClass: TFormClass;FormName:Pointer);
    begin
      if not assigned(FormName) then
      begin
        with FormClass.Create(self)do
        try
          show;
        except
          free;
        end;
      end else
        show;
    end;调用:ShowAddForm(TForm1,Form1)
    结果总是会创建多个窗口的实例。
      

  2.   

    可以用这个方法:
    function AddNewForm(AclsForm: TFormClass): TForm;
    var
      iIndex: Integer;
    begin
      Result := nil;
      //遍历是否类类型相同的窗体
      for iIndex := 0 to Screen.FormCount - 1 do begin 
        if (Screen.Forms[iIndex].ClassType = AclsForm) then begin
          Result := Screen.Forms[iIndex];
          break;
        end;
      end;
      if not Assigned(Result) then begin
        Result := AclsForm.Create(Application);
      end;
      Result.Show;
    end;