View Full Version : How to check if class instance variable was actually initialized?
Darkhog
20-06-2013, 03:27 PM
How can I do that? Do I check for nil equality or something? I need that for destructor in one of my classes - some of class variables may or may not be created when class is destroyed (they're created as necessary) and I need safe way to tell if they were created or not and if they were, destroy them.
imcold
20-06-2013, 04:01 PM
Assign nil to them in class constructor and check for nil (or use Assigned()) in destructor.
SilverWarior
20-06-2013, 04:16 PM
How can I do that? Do I check for nil equality or something? I need that for destructor in one of my classes - some of class variables may or may not be created when class is destroyed (they're created as necessary) and I need safe way to tell if they were created or not and if they were, destroy them.
That is why SomeClass.Free; is there. When you call SomeClass.Free it automatically checks to see if the calss was created and Destroys it if it Was.
Delphius
14-07-2013, 12:25 AM
It is worthwhile to also consider the fact that something is free, and another thing is set to nil.
Hence, there is also the procedure FreeAndNil. ;)
Sorry for my poor english.
Regards,
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.