Form2 := TForm2.Create(Form1);
{........}
Form1.Free;

解决方案 »

  1.   

    Form2 := TForm2.Create(application);   //不能是form1,要不应用程序都关闭了!
    form2.show;
    Form1.Free; 
      

  2.   

    procedure ANewForm(FormClass: TFormClass; var Reference; const FormName: string);
    procedure CloseForm;procedure ANewForm(FormClass: TFormClass; var Reference; const FormName: string);
    begin
      if FindGlobalComponent(FormName) <> nil then exit;
        Application.CreateForm(FormClass,Reference);  //创建新的窗体  if Aform <> nil then  //释放之前的已经创建的窗体
        Aform.Release;  Aform := (FindGlobalComponent(FormName) as TForm); //吧新窗体赋值给aform变量  Aform.parent := Fmain.panel1; //放置新窗体
      Aform.align := alclient;
      Aform.show;
    end;procedure CloseForm;
    begin
      if Aform <> nil then
        Aform.close;
      Aform := nil;
    end;应用时:
      if findglobalcomponent('Form1') = nil then   //判断窗体是否存在
        ANewForm(TForm1,Form1,'Form1');