delphi - How to free an object from within one of its own methods? -


is there way safely free object within 1 of own methods? (i don't need nil objects variable)

var   msg: tamessage; begin   msg := tamessage.create();   msg.processanddone; end; 

and want tamessage.processanddone() method destroy object (in above case msg) because won't need object after calling processanddone method, , don't want call free or destroy each time right after call processanddone (for sake of code clarity).

i know setting tthread's freeonterminate property actual freeing process handled wrapper called threadproc calls thread's execute within.

if last act of processanddone call destroy, or free, fine. if processanddone calls methods, or refers members, after has been destroyed, it's no good. , of course, you'd need put try/finally inside processanddone make sure destruction happens.

but said, should not this. patterns exist clarity, , benefit of other readers. whenever see

obj := tmyobject.create; 

we expect see try/finally block call free. don't go against grain.


Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -