Destructor class in TObject and NIL Delphi

醉酒当歌 提交于 2019-12-02 08:18:36

Explanation:

The variable a will only become nil when it is assigned nil. That means there needs to be a := nil in code, which is now missing.

Free is just a method, working on an instance of the Ta class. Free destroys that instance to which a pointed. The value of a is still the same and now points to a memory address where once was an Ta instance.

Solution:

Use FreeAndNil(a) to simultaneously destroy the object to which the variable points to and nillify the variable.

An instance method cannot modify the instance variable on which the method was invoked. That's because a method is passed a copy of the instance variable (the implicit Self parameter) rather than being passed a reference to the instance variable.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!