Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Testing if an object is an instance of a class
Message
De
07/10/2005 06:23:30
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
 
À
07/10/2005 05:47:32
Information générale
Forum:
Visual FoxPro
Catégorie:
Programmation Orientée Object
Versions des environnements
Visual FoxPro:
VFP 9
Divers
Thread ID:
01057071
Message ID:
01057088
Vues:
14
>In case anybody wants it too :
>
>FUNCTION InstanceOf
>	LPARAMETERS oObject,cClassName
>	LOCAL laClassHierarchy,lcClassName,llResult
>	DIMENSION laClassHierarchy[1]
>	IF VARTYPE(oObject)!="O"
>		MyError("Parameter oObject must be of object type")
>	ENDIF
>	IF VARTYPE(cClassName)!="C"
>		MyError("Parameter cClassName must be of character type")
>	ENDIF
>	lcClassName=UPPER(cClassName)
>	ACLASS(laClassHierarchy,oObject)
>	IF ASCAN(laClassHierarchy,lcClassName)>0
>		llResult=.T.
>	ELSE
>		llResult=.F.
>	ENDIF
>	RETURN llResult
>ENDFUNC
>
David,
You wouldn't mind me shortening code a bit I hope:
FUNCTION InstanceOf
	LPARAMETERS oObject,cClassName
	local array laClassHierarchy[1]
	IF VARTYPE(oObject)!="O"
		MyError("Parameter oObject must be of object type")
	ENDIF
	IF VARTYPE(m.cClassName)!="C"
		MyError("Parameter cClassName must be of character type")
	ENDIF
	
	return ACLASS(laClassHierarchy,oObject) > 0 and ;
               ASCAN(laClassHierarchy,m.cClassName,1,-1,1,1+2+4)>0
ENDFUNC
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform