现有一字符类型的变量str,它存储的是一个窗体的类名,如:TForm1,如何由str将类名为str的窗体创建出来???
解决后可以加分!

解决方案 »

  1.   

    注册该窗体类 TForm1
    然后用 FindComponet() 找到该类, 就下来就很简单了!
      

  2.   

    //根据窗体的名字建
    procedure TForm1.Button1Click(Sender: TObject);
    var
      i: Integer;
      FreeButton: TButton;
    const
      NameForm = 'TForm';
    begin
      i := 2;
      TForm.Create(Self).Name := NameForm + IntToStr(i);
      with TForm(FindComponent(NameForm + IntToStr(i))) do
      begin
        ShowModal;
        free;
      end;
    end;
      

  3.   

    if str = 'TForm1' then
      width TForm1.Create do
      begin
        Showmodual;
        free;
      end;
      

  4.   

    哦,写错了应是
    with TForm1.Create do
      

  5.   

    http://expert.csdn.net/Expert/topic/2348/2348755.xml?temp=.7885706
      

  6.   

    Function TFrm_Main.PRF_Openwindow(as_Fromname:string):integer;
    var
        FcType : TFormClass;
        Frmname:string;
    begin
        try
            Frmname:=  as_Fromname;
            FcType := TFormClass(FindClass(Frmname));
            Application.CreateForm(Fctype,OpenWindow);
            OpenWindow.Showmodal;
        except
            ShowMessage('Form Type not exist,you must register it first');
        end;
        Result := 0;
    end;
    需要在pas文件中加
    initialization
        RegisterClass(窗体类名);
      

  7.   

    忘了一句
    var
        OpenWindow :TForm;