Click or drag to resize

IsMethodClass Function

X#
Check whether a particular method can be sent to a class.

Namespace:  XSharp.RT
Assembly:  XSharp.RT (in XSharp.RT.dll) Version: 2.19
Syntax
 FUNCTION IsMethodClass(
	symClass AS STRING,
	symMethod AS STRING
) AS LOGIC
Request Example View Source

Parameters

symClass
Type: String
A class name as symbol.
symMethod
Type: String
The method name, specified without parentheses.

Return Value

Type: Logic
TRUE if the specified method is defined for the class of the specified object; otherwise, FALSE.
Remarks
Examples
This example uses IsMethodClass() to check whether a class is capable of making sounds:
X#
 1CLASS Animal
 2    EXPORT sound, weight
 3CONSTRUCTOR(s, w)
 4    sound := s
 5    weight := w
 6METHOD Speaks
 7    QOut(sound)
 8END CLASS
 9CLASS Programmer
10    EXPORT language
11CONSTRUCTOR(lang)
12    language := lang
13METHOD Speaks
14    QOut(language)
15    QOut("Hello World")
16    QOut(Chr(7))
17END CLASS
18
19Function Start()
20    LOCAL dog AS Animal
21    LOCAL hacker AS Programmer
22    dog := Animal{"Bark Bark!", 50}
23    hacker := Programmer{"VO"}
24    IF IsMethodClass(#Animal, #Speaks)
25        dog:Speaks()                // Says Bark Bark
26    ENDIF
27    IF IsMethodClass(#Programmer, #Speaks)
28        hacker:Speaks()            // Says VO
29                                // Says Hello World
30                                // Rings a bell
31    ENDIF
See Also