请问把一个from名字放在一个变量中,在程序中如何打开该from

解决方案 »

  1.   

    {打开工作窗口的通用过程}
    {
    OpenForm(TfrmType,frmType,Self)
    }
    procedure TFrmMain.OpenForm(FormClass:TFormClass;Var fm;AOwner:TComponent);
    var
        i,li_max:Integer;
        Child:TForm;
    begin
        {总的窗口数}
        li_max:=Screen.FormCount-1;
        for i:=0 to li_max do
        begin
            {若窗口已经打开,就重新显示}
            if Screen.Forms[i].classType=FormClass then
            begin
                Child:=Screen.Forms[i];
                if Child.WindowState=wsMinimized then
                    ShowWindow(Child.Handle,SW_SHOWNORMAL)
                else
                    ShowWindow(Child.Handle,SW_SHOWNA);
                if (not Child.Visible) then
                    Child.Visible:=True;
                Child.BringToFront;
                Child.SetFocus;
                TForm(fm):=Child;
                Exit;
            end;
        end;
        {由窗口的引用类创建窗口对象}
        Child:=TForm(FormClass.NewInstance);
        TForm(fm):=Child;
        Child.Create(AOwner);
    end;
    procedure TfrmMain.CustomItem6Click(Sender: TObject);
    begin
        OpenForm(Tfrmjssq,frmjssq,self);
    end;
      

  2.   

    用run time type information
      

  3.   

    Function TFrm_Main.PRF_Openwindow(as_Fromname:string):integer;
    var
        FcType : TFormClass;
        Frmname:string;
    begin
        try
            Frmname:= 'T' + 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;备注 ;你要将所有的窗体加上
     initialization
    RegisterClass(窗体类名如tform1);
      

  4.   

    var formname:string;
      Application.CreateForm(TForm1, formname);
    //TForm1就是该窗口的类型根据你的定义而不同