Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Testing if an object is an instance of a class
Message
From
07/10/2005 06:23:30
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
07/10/2005 05:47:32
General information
Forum:
Visual FoxPro
Category:
Object Oriented Programming
Environment versions
Visual FoxPro:
VFP 9
Miscellaneous
Thread ID:
01057071
Message ID:
01057088
Views:
13
>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
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform