FormDestroy和Destroy中选其一个使用.

FormDestroy和Destroy都是执行Free时执行的两个函数

FormDestroy是事件, Destroy是析构函数.FormDestroy是在Destroy中执行的事件,是为了方便程序员写释放资源的代码.

在程序中要么用直接用Destroy释放,要么用FormDestroy事件,不要混合使用.

都知道写Destroy的一般都是

destructor Destroy()

begin

   CdsMain.Free;

   inherited destroy;//保证基类的资源释放, FormDestroy是在TCustomForm中的事件

end;

所以FormDestroy是发生在Destroy的最后一部份,如果你在Destroy中使用了CdsMain.Free

而你再想在FormDestroy中写上CdsMain.Cancel,必然就会发生AV错误.

 

写给初学者.....

D10.Mofen

posted @ 2008-07-08 11:04  D10.天地弦  阅读(539)  评论(0编辑  收藏  举报