打印本文 打印本文 关闭窗口 关闭窗口
The Delphi Object Model (PART I)
作者:武汉SEO闵涛  文章来源:敏韬网  点击数4187  更新时间:2009/4/23 18:43:49  文章录入:mintao  责任编辑:mintao
structor, but you must not redeclare the Free method. When freeing an object, you should call the Free method and not the destructor. The distinction is important, because Free checks whether the object reference is nil and calls Destroy only for non-nil references. In extraordinary circumstances, a class can redefine the Free method (such as TInterface in the seldom-used VirtIntf unit), which makes it that much more important to call Free, not Destroy.

If a constructor or AfterConstruction method raises an exception, Delphi automatically calls the object''''s destructor. When you write a destructor, you must remember that the object being destroyed might not have been completely constructed. Delphi ensures that all fields start out at zero, but if the exception occurs in the middle of your constructor, some fields might be initialized and some might still be zero. If the destructor just frees objects and pointers, you don''''t need to worry, because the Free method and FreeMem procedure both check for nil pointers. If the destructor calls other methods, though, always check first for a nil pointer.

上一页  [1] [2] [3] [4] [5] 

打印本文 打印本文 关闭窗口 关闭窗口