Wiki Home

VFP 8 EMPTYClass


Namespace: VFP
How many of you test for an object with TYPE("object")="O" AND NOT ISNULL(object) and how many shortcut to using TYPE("object.name")="C" instead, looking for a character value of the name property?

There's a gotcha here, the new "empty" class in VFP8 is truly that, empty. So it has no name property for you to check. It has no class property either, so you can't test an object to see if it is an instance of the empty class.
-- Paul Maskens

No gotcha at all - the trick you mention is only needed in versions of VFP before 6.0, since VARTYPE() will correctly return "X" for a reference that is null. So if you're using an empty class, you don't need the trick. Just check with VARTYPE().
-- Ed Leafe

Ed, I agree with VARTYPE() and I'm kicking myself for not mentioning it, but disagree on the impact. Just asking around the office here, the dismay on people's faces when I told them their cute object.name test wouldn't work was amazing.
One person even went so far as to say that he would ban the use of the empty class! Or at least mandate that it always had a name property.
I think that comes from maintaining a code base started in VFP 3 with insufficient resources to rework it.
I wondered how prevalent that "old" shortcut trick might be out in the real world.
-- Paul Maskens

I think your co-workers are over reacting. The Empty class is not really a new idea, considering we've had SCATTER NAME for quite some time, which is really an empty class with the Add Property()s already done for you. If they're indiscriminately using the Type("object.name") against any object reference, it would have failed on those objects too, even before VFP8 when the Empty class became publically instantiable. -- Mike Helland

I agree, we nearly got EMPTY in VFP 3 didn't we?
I was surprised at the reaction, too. But wondered how attitudes are outside our little pocket of history (we just rolled out VFP7!).
-- Paul Maskens

Add to this the fact that you cannot subclass the Empty class, and the above problem now only applies to SCATTER NAME objects (as always) and parameter objects (created by x=CREATE("EMPTY").. Add Property(x,'prop','val'). Personally, I had expected to subclass Empty, expecting it to be the new lightest-weight base class. - wgcs
Category VFP Tips And Tricks
( Topic last updated: 2004.04.26 01:24:18 PM )