How to detect “dangling pointers” if “Assigned()” can’t do it?

If you have an object variable in scope and it may or may not be a valid reference, FreeAndNil is what you should be using. That or fixing your code so that your object references are more tightly managed so it’s never a question.

Access Violations shouldn’t be thought of as an enemy. They’re bugs: they mean you made a mistake that needs fixed. (Or that there’s a bug in some code you’re relying on, but I find most often that I’m the one who screwed up, especially when dealing with the RTL, VCL, or Win32 API.)

Leave a Comment