请教一个问题,如何关闭一个动态创建的窗体(通过点饥窗体上的按钮 )

解决方案 »

  1.   

    有多种方法
    1.直接Close 动态创建的窗体.Close;
    2. PostMessage(动态创建的窗体.Handle,WM_CLOSE,0,0);
      

  2.   

    up
    楼上说的好,不过强烈建议用freeandnil 代替free
      

  3.   

    谢了,用free 和 freeandnil有什么不同,用destroy可以吗?
      

  4.   

    onclose 事件中加入action:=caFree;
    onDestroy事件中加入self:=nil;
    ButtonClick事件加入self.close;
    这样无论单击按钮或者从窗体右上角关闭都可以了。
      

  5.   

    Use FreeAndNil to ensure that a variable is Nil after you free the object it references. 我要记下来,不过ensure that a variable is Nil after you free有什么好处