What delphi function asserts that an object is not nil?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Like knight_killer pointed out above, you use the
Assert()function, asserting thatAssigned(obj)istrue. Of course, like in most compiled languages, assertions are not executed (or even included in the compiler output) unless you’ve specifically enabled them, so you should not rely on assertions for release mode builds.You can, of course, simply check against
nil, a laAssert(obj <> nil). However,Assigned()produces the exact same compiler output and has the added benefit that it works on pointers to class methods too (which are in reality a pair of pointers, one to the method, and the other one to the class instance), so usingAssigned()is a good habit to pick up.