当然不行,因为参数不是字符串var
   form2:TForm2;
begin
   if not assigned(form2) then
      form2:=TForm2.Create(Application);
end;

解决方案 »

  1.   

    换个思路:if findwindows(..) then ... else application.createform()
      

  2.   

    达到该目的只需
    if form2<>nil then application.create(tform2,form2);、
    至于指字符串转变为form
    用if 语句判断即可
      

  3.   

    function IsCreate(form:string):boolean;
    var i:integer;
    begin
      Result:=false;
      for i:=0 to Application.ComponentCount-1 do
        if Application.Components[i].ClassNameIs(form) then
        begin
          Result:=true;
          Exit;
        end;
    end;
      

  4.   

    请自行参详,或许有用
    //InternalFindShowForm(FormClass, Caption, True);
    function InternalFindShowForm(FormClass: TFormClass;
      const Caption: string; Restore: Boolean): TForm;
    var
      I: Integer;
    begin
      Result := nil;
      for I := 0 to Screen.FormCount - 1 do begin
        if Screen.Forms[I] is FormClass then
          if (Caption = '') or (Caption = Screen.Forms[I].Caption) then begin
            Result := Screen.Forms[I];
            Break;
          end;
      end;
      if Result = nil then Application.CreateForm(FormClass, Result);
      with Result do begin
        if Restore and (WindowState = wsMinimized) then WindowState := wsNormal;
        Show;
      end;
    end;
      

  5.   

        谢谢Hjandy,将你提供的函数稍微修改后,就可以使用了。这个函数很有用,它至少让我少写一万代码,解决了我的难题。实在感激不尽!!!。
    function InternalFindShowForm(const WindowsName: string; Restore: Boolean): TForm;
    var
      I: Integer;
    begin
      Result := nil;
      for I := 0 to Screen.FormCount - 1 do begin
        if Screen.Forms[I] is TForm then
          if (WindowsName = '') or (WindowsName = Screen.Forms[I].Name) then begin
            Result := Screen.Forms[I];
            Break;
          end;
      end;
      if Result = nil then Application.CreateForm(TForm, Result);
      with Result do begin
        if Restore and (WindowState = wsMinimized) then WindowState := wsNormal;
        Show;
      end;
    end;
      
        应用实例:
    procedure TForm1.Bitbtn1Click(Sender:TObject)
    var
        StrTemp:String;
    begin
      StrTemp:='Form2';//Form2已经存在,现在准备创建
      InternalFindShowForm(StrTemp,True);
    end;  
      

  6.   


    var
      Form1:TForm;
    begin
      Form1 := TForm.Create(Self); 
      Form1.Name := 'frmMDIChild1' ;
    end;