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 05:24:06
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
07/10/2005 05:05:15
General information
Forum:
Visual FoxPro
Category:
Object Oriented Programming
Environment versions
Visual FoxPro:
VFP 9
Miscellaneous
Thread ID:
01057071
Message ID:
01057075
Views:
16
This message has been marked as the solution to the initial question of the thread.
>Hello,
>
>When testing parameters given to a function, I was wondering if there was a simple way to test whether an object x is an instance of a custom class A when inheritance is involved.
>For example, class A inherits from Custom, class B inherits from class A, class C inherits from class B and I want to test object x so that it would answer indifferently yes whether the Class property of x is A, B or C. Unfortunately with the ParentClass property I can recurse only up one level.
>Said otherwise, I would need is to construct is a function InstanceOf(oObject,cClassName), returning .T. if and only if the class of oObject is cClassName or one of its subclasses.
>
>Thank you for your help,
>
>David

You mean aclass()?
Local o,ix
o = CreateObject('myD')
For ix = 1 to AClass(aHierarchy,o)
 ? aHierarchy[m.ix]
endfor

Define Class myA as Custom
EndDefine

Define Class myB as myA
EndDefine

Define Class myC as myB
EndDefine

Define Class myD as myC
EndDefine
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