TContractMain = class(TFrame)  
.......
    public
      constructor Create(AOwner: TComponent);Override;      destructor Destroy; override;
   end
constructor TContractMain.Create(AOwner: TComponent);
begin
   Inherited create(AOwner);   DModule.GetCompanyInfor(cmBox_Company);
end;destructor TContractMain.Destroy;
begin
   showmessage('1');
   inherited Destroy;
end;在使用该 Frame 时 为什么 Destroy 没有执行

解决方案 »

  1.   

    顺便再问一下 为什么  用 reintroduce;  重写 构造函数时  类对象必须声明成 全局 的 才可以 调用 FreeAndNil  否则就不可以 请问为什么?
    是不是 我得 有问题
    TFrmMainInfor = class(TForm)
    public
    constructor Create(AOwner: TComponent;const FMainInforType:TMainInforType);reintroduce; 
    end
      

  2.   

    补充一下  除非 我自己调用了 Fram  所在 窗口的 Free  函数
      

  3.   

       Application.CreateForm(TForm3, Form3);
       Form3.ShowModal;//Form3 上面有TContractMain  //Frame  控件
      

  4.   

    //Frame 对象 编写 
    unit Unit2;interfaceuses 
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
      StdCtrls;type
      TFrame2 = class(TFrame)
        Button1: TButton;
        CheckBox1: TCheckBox;
      private
        { Private declarations }
      public
        constructor Create(AOwner: TComponent); override;
        destructor Destroy; override;
      end;implementation{$R *.dfm}constructor TFrame2.Create(AOwner: TComponent);
    begin
       showmessage('Create');
       inherited Create(AOwner);end;destructor TFrame2.Destroy;
    begin
       showmessage('Destroy');
       inherited Destroy;
    end;end.
    //*************************************
    //在 Form3  上添加  TFrame2 
    //*******************************unit Unit3;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, Unit2;type
      TForm3 = class(TForm)
        Frame21: TFrame2;
        procedure FormDestroy(Sender: TObject);
        procedure Frame21Button1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form3: TForm3;implementation{$R *.dfm}procedure TForm3.FormDestroy(Sender: TObject);
    begin//showmessage('2222');
    sleep(1000);
    end;procedure TForm3.Frame21Button1Click(Sender: TObject);
    begin
       self.Close;
    end;end.
    ///***********调用****************unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, Unit2, StdCtrls;type
      TForm1 = class(TForm)
        Button1: TButton;
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementationuses Unit3;{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
    begin
       Application.CreateForm(TForm3, Form3);
       Form3.ShowModal;  // FreeAndNIl(Form3);
    end;end.
    为什么 关闭 Form3 时 不执行  TForm3.FormDestroy  和  TFrame2.Destroy;
      

  5.   

    你都没有释放Form3,当然不会执行啦!Application.CreateForm(TForm3, Form3); 
    try
      Form3.ShowModal; 
    finally
      FreeAndNil(Form3);
    end;
      

  6.   

    TO :chenzhuo 
    谢谢 你啊 ,我还一直都以为 如果Close 了 它就会自动执行 destroy  来释放资源 。原来不是的,还要显式来释放 ,呵呵,谢谢 你啊 !