1. Computing

No Access Violation For Me - Return a Property Value From a Nil Delphi Object

By October 31, 2011

Follow me on:

in OOP in Delphi :: When a Delphi object type variable is nil, accessing any of the object properties would blow an access violation exception to the user. Sometimes you simply need nil objects to return some kind of a default value. Here's how to have an object return simple values even when it has not been assigned.

Read the full article to learn how to Don't Check For Assigned - Ensure Your Nil Delphi Objects Return Property Values

Related:

Comments
October 31, 2011 at 2:20 pm
(1) Silver Warior says:

I personally think that this aproach is werry WERRY BAD! Why?
1. By using this approach you do get rid of Acces Violation messages, but infact you are making your code much harder to debug. Why? Sure your program would specify that object isn’t assigned, but you won’t even have a clue wich object isn’t assigned and where in the actual code this happended.
2. If you have object with lots of properties you would probably end up with more code.
3. If you wan’t to check thether the object has been assigned or not you would still need to use one conditional clause (mostlikly if clause) but instead of checking if your object variable is pointing to actual object you would be checking if two strings are the same, wich is much slower (could result in much slower application).

Leave a Comment

Line and paragraph breaks are automatic. Some HTML allowed: <a href="" title="">, <b>, <i>, <strike>

©2014 About.com. All rights reserved.