我要用一个字符串变量(代表窗体名) 打开窗体
动态创建更好

解决方案 »

  1.   

    http://search.csdn.net/search.asp?key=registerclass&class=Delphi&size=10&option=advance&x=50&y=6————————————————————————————————————
    宠辱不惊,看庭前花开花落,去留无意;毁誉由人,望天上云卷云舒,聚散任风。
    ————————————————————————————————————
      

  2.   

    我的问题是这样的,主窗体mainfrom上有一个添加按钮button1
    我现在打开的另一个窗体form1 我要实现一点主窗体上的添加就打开from1Tj(这个窗体先做好的是与form1相对应的),而打开form2时点添加就能弹出form2Tj
    现在就是想知道 button1.onclick事件怎么写呀?
      

  3.   

    begin
      CreateAndOpen(TFormTj, newForm);
    end;procedure CreateAndOpen(FormType: TFormClass; var aForm: TForm);
    begin
      Application.CreateForm(FormType, aForm);
    end;
      

  4.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;type
      TForm1 = class(TForm)
        Button1: TButton;
        Button2: TButton;
        Button3: TButton;
        procedure Button1Click(Sender: TObject);
        procedure Button2Click(Sender: TObject);
        procedure Button3Click(Sender: TObject);
      private
      procedure ShowForm(str:string);
        { Private declarations }
      public
      str:string;
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}
    procedure Tform1.ShowForm(str:string);
    var
      fmname:TForm;
    begin
      if GetClass(str)<>nil then
       begin
         fmname:=TFormClass(FindClass(str)).Create(self);
         fmname.show;
      end;
    end;procedure TForm1.Button1Click(Sender: TObject);
    begin
    showform(str);
    end;procedure TForm1.Button2Click(Sender: TObject);
    begin
    str:='Tform2';
    end;procedure TForm1.Button3Click(Sender: TObject);
    begin
    str:='Tform3';
    end;end.
    ---------------------
    unit Unit2;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs;type
      TForm2 = class(TForm)
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form2: TForm2;implementation{$R *.dfm}Initialization
      RegisterClass(TForm2);
    Finalization
      UnRegisterClass(TForm2);end.---------------------------
    unit Unit3;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs;type
      TForm3 = class(TForm)
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form3: TForm3;implementation{$R *.dfm}
    Initialization
      RegisterClass(TForm3);
    Finalization
      UnRegisterClass(TForm3);end.
    谢谢大家!结贴