Seen some code lately that uses
if MyObject = ? then
and some that uses
if valid-object(MyObject) then
Is there any reason to prefer one over the other ... other than the usual matter of taste?
prefer the latter as it shows intent better imho
On 22 March 2012 22:11, Thomas Mercer-Hursh <
Right, I am so inclined by style ... but wondering if there is any actual difference.
Because ? isn't enough in the ABL when it comes to objects and procedures (and buffer handles, query handles).
In other languages like java and C# setting a variable to null (in ABL's case unknown) effectively deletes the object as long as there are no other references to that object. Also in these languages an object is never "invalid" as far as the language is concerned. If you have a reference to it, you can call methods and access properties and fields. You cannot have a "deleted" object (well...except in .NET when talking about finalizers and zombie objects...but we don't need to go there).
Whereas, in the ABL you can have a reference to an object, but that object may or may not be valid because it can be deleted, and attempting to access it will result in invalid handle errors; same thing with procedures.
So you can safely set your objects to ? and test against that, but if your objects have a life outside of the current execution scope, then you need to use valid-object. More specificaly, if you ever use the DELETE OBJECT statement, then testing for ? isn't enough and you'll need to start using the VALID-OBJECT() function.
mattB