Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Determining if a Property Exists
Message
De
25/07/2001 13:10:06
Nancy Folsom
Pixel Dust Industries
Washington, États-Unis
 
 
À
25/07/2001 12:59:46
Information générale
Forum:
Visual FoxPro
Catégorie:
Gestionnaire d'écran & Écrans
Divers
Thread ID:
00534933
Message ID:
00535162
Vues:
15
>>>PemStatus() or Type()... Is there advantage of using one over the other?
>>If you're simply trying to determine whether or not the property exists, TYPE() takes less code.
>
>Here's something obscure, be careful with type() because you'll fire Access methods of the property you want. That may be something you want, or not. That also includes this_access, I've used parameters objects that will automatically create properties you ask for on the object, and using Type() returned something I didn't want.
>
>If you just wanna know if the prop is there, PEMStatus() is the safest way to go.

I think your point here and a benchmark test I just ran has convinced me to finally give up my superstition about PEMSTATUS. I got burned by its infamous dangling object reference bug :-(.

Anyway, here's the benchmark I just ran.
#DEFINE LOOPS 5000
LOCAL lo, lni, lnSeconds
lo = NEWOBJECT( 'MyTest', 'Temp.PRG' )

CLEAR 

? "Test for PEMSTATUS call on an exising Property: "
lnSeconds = SECONDS()
FOR lni = 1 TO LOOPS
	PEMSTATUS( lo, "MyProp", 5 )
NEXT
?? SECONDS() - lnSeconds && 0.050

? "Test for TYPE() call on an exising Property: "
lnSeconds = SECONDS()
FOR lni = 1 TO LOOPS
	=TYPE( "lo.MyProp" )
NEXT
?? SECONDS() - lnSeconds && 0.121

? "Test for VARTYPE() call on an exising Property: "
lnSeconds = SECONDS()
FOR lni = 1 TO LOOPS
	VARTYPE( lo.MyProp )
NEXT
?? SECONDS() - lnSeconds && 0.060

? "Test for PEMSTATUS call on a nonexistent Property: "
lnSeconds = SECONDS()
FOR lni = 1 TO LOOPS
	PEMSTATUS( lo, "NotMyProp", 5 )
NEXT
?? SECONDS() - lnSeconds && 0.040

? "Test for TYPE() call on a nonexistent Property: "
lnSeconds = SECONDS()
FOR lni = 1 TO LOOPS
	=TYPE( "lo.NotMyProp" )
NEXT
?? SECONDS() - lnSeconds && 0.180

? "Test for VARTYPE() call on a nonexistent Property: "
lnSeconds = SECONDS()
FOR lni = 1 TO LOOPS
	VARTYPE( lo.NotMyProp )
NEXT
?? SECONDS() - lnSeconds && 0.040

DEFINE CLASS MyTest AS Session
	MyProp = "Hello!"
ENDDEFINE
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform