write the code in TParentForm 's OnDestory event 
as : self:=nil then the TchildForm will inherit this statement and execute 

解决方案 »

  1.   

    对,在父类的OnDestroy中写self := nil就行了
    如在子类的OnDestroy有别的动作,在用一下Inherited
      

  2.   

    我原来就用这方法的,但得不到所要的结果(Assigned(ChildFormX)仍然还是返回TRUE)
      

  3.   

    欧,刚才试了一下,确实不好使,想了一下,可能是这个原因吧
    在TParentForm.Destroy(Sender: TObject)中
    编译器在执行期是加了一个self参数,只是加了一个当前实例引用
    的一拷贝值,如果self是变量参数的话,我想就应该行了,呵呵,但不行
    不知有没有别的方法
      

  4.   

    如果self为拷贝值的话,这好像不符面向对象原理
      

  5.   

    我是这个意思,好像编译器在运行时对于TParentForm.Destroy加一Self
    即为TParentForm.OnDestroy(Sender: TObject;Self: TParentForm);
    好像是这样子
    而此时当它的子类释放时,当调用OnDestroy时,则调用祖先的OnDestroy,而此时的Self对应
    的是子类实例,但这时的参数为数值参数,只是把参数Self的值改为nil,而实例仍然未改
    如果是这样子,就好了
    TParentForm.OnDestroy(Sender: TObject;var Self: TParentForm);
      

  6.   

    to xzgyb  很感谢你 
    我知道你的意思,那能不能用什么编译器开关来改变呢
      

  7.   

    有了,你试一试,在TParentForm中写这几句
    TParentForm = class(TForm)
      procedure FormClose(Sender: TObject; var Action: TCloseAction);
      private
        FInstance : ^TForm;
      public
        constructor Create(AOwner:TComponent; var FRef:TForm);
        destructor Destroy;override;
    end;implementation
    constructor TParentForm.Create(AOwner:TComponent; var FRef: TForm);
    begin
      FInstance := @FRef;
      Inherited Create(AOwner);
    end;
    destructor TParentForm.Destroy;
    begin
      Inherited;
      FInstance^ := nil;
    end;
    procedure TParentForm.FormClose(Sender: TObject; var Action: TCloseAction);
    begin
       Action := caFree;
    end;以后创建子窗口就
    ChildForm1 := TChildForm1(Application, ChildForm1);
    OK?,好用可要加分呀,呵呵
      

  8.   

    写错了
    创建子窗口时应为ChildForm1 := TChildForm1.Create(Application, TForm(ChildForm1));
      

  9.   

    to xzgyb
    这方法很好,加分是肯定的
    可惜我代码已经完成了,就差这项功能,所以去修改所有子窗体的Create函数,有点麻烦
    如果事先就用你这方法的法,倒是很好。
    不知道大家还有没别的方法,只要修改父类就可
      

  10.   

    创建时
    先判断form是否为nil
    if form=nil then
      application.createform(tform,form);
    form.show;or form.showmodal;
    在form的onclose事件中加
    action:=cafree;
    form:=nil;
      

  11.   

    to snjun
    你说的没错,不过我想把这些代码放入父类中实现
      

  12.   

    不改Create参数你就将FInstance : ^TForm放到public中,在Create语句后赋值即可。也可以做成可写属性呵呵。如果不放心是否每个Create都改了程序,在FormCreate中加Assert断言判断。