你在Form1单元中引用Form2,在Form2单元中引用Form3,在Form3单元中引用Form2,然后
在Form1中创建Form2这一个不用我写了吧
Form2中创建Form3也不用写了吧
Form3的OnClose中写入:
Form2.Close;
Close;就可以了

解决方案 »

  1.   

    form2中這麼創建form3;
    procedure TForm2.Button1Click(Sender: TObject);
    var
       test2:TForm3;
    begin
       test2:=TForm3.Create(Application);
       test2.show;
    end;procedure TForm3.Button1Click(Sender: TObject);
    begin
        close;
        Form2.Close ;
        Form2.free;
    end; 换个顺序就成了。不能先delete再close的。
      

  2.   

    是啊,你都把它free了,还怎么close啊,把form2.free注掉。
    另:在创建之前要怎么做
    if NOT assigned(form1) then begin
      form1 := tform1.create(...);
      ....
    end;
    在formclose里写上form1 := nil;
    好象就这些了吧,你试试看
      

  3.   

    這兩句我是取其一的.  我當然知道不能一起執行.   Form2.free;  --->>執行這一句根本不關閉Form2.
     //Form2.Close ;--->>執行這一句報錯'報'access violation at address '
      

  4.   

    這兩句我是取其一的.  我當然知道不能一起執行.   Form2.free;  --->>執行這一句根本不關閉Form2.
     //Form2.Close ;--->>執行這一句報錯'報'access violation at address '
      

  5.   

    procedure TForm3.Button1Click(Sender: TObject);
    begin       
        Form2.Close ;
        Form2.free;  //这句可以不要,因为你创建Form2时已指定Application管理她的释放
        close;end;
    —————————————————————————————————
    MaximStr := '宠辱不惊,看庭前花开花落,去留无意;
                 毁誉由人,望天上云卷云舒,聚散任风。';
    if Not Assigned(I) then
      I := TI.Create(Nil);
    I.Maxim := MaximStr;
    I.Explain := '假如上述代码中出现“OA”、“3D”等字样,改为“=”等';
    I.Desire := '加不加分随你';
    —————————————————————————————————
           
      

  6.   

    to : Linux2001(猪!是怎么死的) 
       不對. 您試過沒有哇??
      

  7.   

    to : Linux2001(猪!是怎么死的) 
        您試我的代嗎.
    form1中的代嗎;
      procedure TForm1.Button1Click(Sender: TObject);
    var
       test1:TForm2;
    begin
       test1:=TForm2.Create(Application);
       test1.show;
    end;form2中的代嗎;
    procedure TForm2.Button1Click(Sender: TObject);
    var
       test2:TForm3;
    begin
       test2:=TForm3.Create(Application);
       test2.show;
    end;form3中的代嗎;
    procedure TForm3.FormClose(Sender: TObject; var Action: TCloseAction);
    begin   Form2.Close ;
       close;
    end;
    我點擊form3窗體的'關閉'系統菜單觸發此事件.但出錯.
    報'access violation at address '. 您把您的代碼貼出來好嗎??
      

  8.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;type
      TForm1 = class(TForm)
        Button1: TButton;
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementationuses Unit2;{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
    var
      a:tform2;
    begin
      a:=tform2.Create(application);
      a.openner:=self;
      a.Show;
    end;end.unit Unit2;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;type
      TForm2 = class(TForm)
        Button1: TButton;
        procedure Button1Click(Sender: TObject);
        procedure FormClose(Sender: TObject; var Action: TCloseAction);
      private
        { Private declarations }
      public
        { Public declarations }
        openner:tform;
      end;var
      Form2: TForm2;implementationuses Unit3;{$R *.dfm}procedure TForm2.Button1Click(Sender: TObject);
    var
      a:tform3;
    begin
      a:=tform3.create(application);
      a.openner:=self;
      a.Show;
    end;procedure TForm2.FormClose(Sender: TObject; var Action: TCloseAction);
    begin
      action:=cafree;
      openner.Close;
    end;end.unit Unit3;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs;type
      TForm3 = class(TForm)
        procedure FormClose(Sender: TObject; var Action: TCloseAction);
      private
        { Private declarations }
      public
        { Public declarations }
        openner:tform;
      end;var
      Form3: TForm3;implementation{$R *.dfm}procedure TForm3.FormClose(Sender: TObject; var Action: TCloseAction);
    begin
      action:=cafree;
      openner.Close;
    end;end.
      

  9.   

    不行,上面的代码太sha,看下面这个就行了:procedure TForm2.Button1Click(Sender: TObject);
    var
      a:tform3;
    begin
      a:=tform3.create(self);
      a.Show;
    end;procedure TForm2.FormClose(Sender: TObject; var Action: TCloseAction);
    begin
      action:=cafree;
      tform(self.Owner).Close;
    end;
    利用create的owner就可以了。
      

  10.   

    其实用:
    Action:=caFree
    就可以解决问题的了。
      

  11.   

    to : peihexian(只有初中学历) 
       form3中就沒有關閉form2的代碼.
      請您看清;    form3關閉時,希望form2也關閉.怎麼寫  ???
      

  12.   

    to : peihexian(只有初中学历) 
      您的第一次帖子好像不對.  第二次帖子好像正確.
      

  13.   

    to  nodefault(永不言败) :
    看来你还真的是个新手,第一个也可以执行,第二个更可以执行了。
    procedure TForm2.Button1Click(Sender: TObject);
    var
      a:tform3;
    begin
      a:=tform3.create(self);
      a.Show;
    end;procedure TForm2.FormClose(Sender: TObject; var Action: TCloseAction);
    begin
      action:=cafree;
    end;
    procedure TForm3.FormClose(Sender: TObject; var Action: TCloseAction);
    begin
      action:=cafree;
      tform(self.Owner).Close;
    end;
    这样可以了吧?
      

  14.   

    to : peihexian(只有初中学历) 
      您的第一次帖子好像不對. 關掉第3個窗體,整個應用程序結束.   a:=tform2.Create(application);
       a.openner:=self; //form1中為什麼要這條語句??
                   //此openner與form2/form3中的openner有什麼聯係???
       a.Show;  第二次帖子正確.
      

  15.   

    to nodefault(永不言败):
    哈哈,小弟,第一个回答中的form1中的opener没用,去了就行了,关键是你要明白如何close打开自己的form.
      

  16.   

    to nodefault(永不言败):
    哈哈,小弟,第一个回答中的form1中的opener没用,去了就行了,关键是你要明白如何close打开自己的form.
      

  17.   

    怎么都那么复杂,在From3关闭的时候,向From2 Post一个关闭消息就不得了?
    PostMessage(From2.Handle,WM_CLOSE ,0,0);
      

  18.   

    呵呵,这种方法很多啊;
    form3.showmodal;
    close;
    就搞定了;
      

  19.   

    to  sogh(青山之音):
    人家的form是动态建立的,这样的话在form3中写form2.XX一定会出错的.
    要不你试试?在project菜单中选options,在create form中把form2和form3去除auto create,然后再试试?
      

  20.   

    to  peihexian(只有初中学历):
     你試試form1中,注釋掉後出錯'access violation at address 'var
      a:tform2;
    begin
      a:=tform2.Create(application);
      //a.openner:=self;   //注釋掉後出錯'access violation at address '
      a.Show;
      

  21.   

    var
      a:tform2;
    begin
      a:=tform2.Create(application);
      a.ShowModal;
      Close;
    end;
    呵呵,您还没有试,就知道我的这个不对?我觉的您应该试一试,看它到底对不对;
      

  22.   

    to  nodefault(永不言败) :
    啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    你不是一般的菜,是我见过的最菜的人!真的,I 服了 U!!!!!!!!!!
      

  23.   

    to  nodefault(永不言败) :
    你告诉我你学了几天delphi了?
      

  24.   

    to  peihexian(只有初中学历):
      您試試;     注釋掉後出錯'access violation at address '
    ----------------------------------------------------------------
    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
      StdCtrls;type
      TForm1 = class(TForm)
        Button1: TButton;
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementationuses Unit2;{$R *.DFM}procedure TForm1.Button1Click(Sender: TObject);
    var
      a:tform2;
    begin
      a:=tform2.Create(application);
      //a.openner:=self; //注釋掉後出錯'access violation at address '  a.Show;
    end;end.
    ----------------------------------------------------------
    unit Unit2;interfaceuses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
      StdCtrls;type
      TForm2 = class(TForm)
        Button1: TButton;
        procedure Button1Click(Sender: TObject);
        procedure FormClose(Sender: TObject; var Action: TCloseAction);
      private
        { Private declarations }
      public
         openner:tform;
        { Public declarations }
      end;var
      Form2: TForm2;implementationuses Unit3;{$R *.DFM}procedure TForm2.Button1Click(Sender: TObject);
    var
      a:tform3;
    begin
      a:=tform3.create(application);
      a.openner:=self;
      a.Show;
    end;procedure TForm2.FormClose(Sender: TObject; var Action: TCloseAction);
    begin
      action:=cafree;
      openner.Close;
    end;end.
    -----------------------------------------------------------
    unit Unit3;interfaceuses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
      StdCtrls;type
      TForm3 = class(TForm)
        Button1: TButton;
        procedure Button1Click(Sender: TObject);
        procedure FormClose(Sender: TObject; var Action: TCloseAction);
      private
        { Private declarations }
      public
          openner:tform;
        { Public declarations }
      end;var
      Form3: TForm3;implementationuses Unit2 ;{$R *.DFM}procedure TForm3.Button1Click(Sender: TObject);
    begin
        close;end;procedure TForm3.FormClose(Sender: TObject; var Action: TCloseAction);
    begin
    begin
      action:=cafree;
      openner.Close;
    end;end;end.
      

  25.   

    linux2001的form2.close;close;好象不可以。
      

  26.   

    to nodefault(永不言败) :
    我就不明白,你真的有这么笨吗?我真的只有初中学历,98年开始学delphi时也没有这么费劲啊?
    算了不和你说了,你说哪有问题我就给你解决哪的问题吧,气死我了。
    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
      StdCtrls;type
      TForm1 = class(TForm)
        Button1: TButton;
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementationuses Unit2;{$R *.DFM}procedure TForm1.Button1Click(Sender: TObject);
    var
      a:tform2;
    begin
      a:=tform2.Create(application);
      a.Show;
    end;end.
    ----------------------------------------------------------
    unit Unit2;interfaceuses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
      StdCtrls;type
      TForm2 = class(TForm)
        Button1: TButton;
        procedure Button1Click(Sender: TObject);
        procedure FormClose(Sender: TObject; var Action: TCloseAction);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form2: TForm2;implementationuses Unit3;{$R *.DFM}procedure TForm2.Button1Click(Sender: TObject);
    var
      a:tform3;
    begin
      a:=tform3.create(application);
      a.openner:=self;
      a.Show;
    end;procedure TForm2.FormClose(Sender: TObject; var Action: TCloseAction);
    begin
      action:=cafree;
    end;end.
    -----------------------------------------------------------
    unit Unit3;interfaceuses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
      StdCtrls;type
      TForm3 = class(TForm)
        Button1: TButton;
        procedure Button1Click(Sender: TObject);
        procedure FormClose(Sender: TObject; var Action: TCloseAction);
      private
        { Private declarations }
      public
          openner:tform;
        { Public declarations }
      end;var
      Form3: TForm3;implementationuses Unit2 ;{$R *.DFM}procedure TForm3.Button1Click(Sender: TObject);
    begin
        close;
    end;procedure TForm3.FormClose(Sender: TObject; var Action: TCloseAction);
    begin
    begin
      action:=cafree;
      openner.Close;
    end;end;end.
      

  27.   

    謝謝 peihexian(只有初中学历) 指點,明白了.