代码如下:unit Unit1;interfaceuses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;type
  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;var
  Form1: TForm1;
implementation
  type
  TForm2 = class(TForm)  private
    { Private declarations }
  public
    { Public declarations }
  end;{$R *.dfm}
   
procedure TForm1.Button1Click(Sender: TObject);
begin
  ShowMessage('helo');
end;
procedure TForm1.Button2Click(Sender: TObject);
var
  Form2: TForm2;
begin
    Application.CreateForm(TForm2, Form2);
    Form2.Show;
end;end.点击Button2后,Form2没有显示出来,为什么?

解决方案 »

  1.   

    unit   Unit1;interface uses 
        Windows,   Messages,   SysUtils,   Variants,   Classes,   Graphics,   Controls,   Forms, 
        Dialogs,   StdCtrls; type 
        TForm1   =   class(TForm)
        Button1: TButton;
        Button2: TButton;
            procedure   Button1Click(Sender:   TObject); 
            procedure   Button2Click(Sender:   TObject); 
        private 
            {   Private   declarations   } 
        public 
            {   Public   declarations   }
        end;
    type
        TEventHandler  = class
        private
            {   Private   declarations   }
        public
            {   Public   declarations   }
        end;
    var
        Form1:   TForm1;
        frm: TForm;
    implementation
    {$R   *.dfm}procedure   TForm1.Button1Click(Sender:   TObject);
    begin 
          ShowMessage('helo');
    end;
    procedure   TForm1.Button2Click(Sender:   TObject);
    begin
       if frm=nil then
         begin
           frm:=Tform.Create(nil);
           frm.Show ;
         End;end; end. 
      

  2.   

    把他改成这样就行啦
    procedure   TForm1.Button2Click(Sender:   TObject); 
    var
    FORM2:TFORM ;
    begin
            Application.CreateForm(TForm,   Form2);
            Form2.Show;end; 
      

  3.   

    不晓得,你这个type有什么用!!??
    上面两位的都可以Show出来
      

  4.   

    把他改成这样就行啦 
    procedure       TForm1.Button2Click(Sender:       TObject);   
    var 
    FORM2:TFORM   ; 
    begin 
                    Application.CreateForm(TForm,       Form2); 
                    Form2.Show; end;   
    确实这样就可以,为什么我的代码不行呢?
      

  5.   

    把他改成这样就行啦 
    procedure       TForm1.Button2Click(Sender:       TObject);   
    var 
    FORM2:TFORM   ; 
    begin 
                    Application.CreateForm(TForm,       Form2); 
                    Form2.Show; end;   
    确实这样就可以,为什么我的代码不行呢?