Click or drag to resize

IsInstanceOf Function

X#
Determine if an object is an instance of a class.

Namespace:  XSharp.RT
Assembly:  XSharp.RT (in XSharp.RT.dll) Version: 2.21
Syntax
 FUNCTION IsInstanceOf(
	oObject AS Object,
	symClassName AS STRING
) AS LOGIC
Request Example View Source

Parameters

oObject
Type: Object
The object to check for.
symClassName
Type: String
A symbolic representation of the class.

Return Value

Type: Logic
TRUE if oObject is an instance of symClassName; otherwise, FALSE.
Remarks
An instance of an inherited class is also an instance of the original (super) class. However, an instance of a super class is not an instance of any of its inherited classes. IsInstanceOf() is similar to CheckInstanceOf() except that it does not generate an error message if the specified object is not an instance of the specified class.
Examples
These examples illustrates IsInstanceOf() on inherited classes:
X#
 1CLASS Employee
 2    EXPORT name, age
 3CONSTRUCTOR(tName, tAge)
 4    name := tName
 5    age := tAge
 6END CLASS
 7CLASS Programmer INHERIT Employee
 8END CLASS
 9CLASS Assembler INHERIT Programmer
10END CLASS
11FUNCTION CheckArgument()
12    LOCAL x, y AS OBJECT
13    x := Employee{"John", "25"}
14    y := Assembler{"Bill", "30"}
15    ? IsInstanceOf(x, #Employee)        // TRUE
16    ? IsInstanceOf(x, #Programmer)        // FALSE
17    ? IsInstanceOf(x, #Assembler)        // FALSE
18    ? IsInstanceOf(y, #Employee)        // TRUE
19    ? IsInstanceOf(y, #Programmer)        // TRUE
20    ? IsInstanceOf(y, #Assembler)        // TRUE
See Also