Executes a named class method in the designated class.
Description
$CLASSMETHOD permits an ObjectScript program to invoke an arbitrary class method in an arbitrary class. Both the class name and the method name may be computed at runtime or supplied as string constants. To invoke an instance method rather than a class method, use the $METHOD function.
If the method takes arguments, they are supplied by the list of arguments that follow the method name. A maximum of 255 argument values may be passed to the method.
The invocation of $CLASSMETHOD as a function or a procedure determines the invocation of the target method. You can invoke $CLASSMETHOD using the JOB command or the DO command, discarding the return value. Like all DO command arguments, $CLASSMETHOD can take a postconditional parameter when called by DO.
An attempt to invoke a nonexistent class results in a <CLASS DOES NOT EXIST> error, followed by the current namespace name and the specified class name. For example, attempting to invoke the nonexistent classname “Fred” results in the error <CLASS DOES NOT EXIST> *User.Fred. Specifying the empty string for classname results in <CLASS DOES NOT EXIST> *(No name).
An attempt to invoke a nonexistent class method results in a <METHOD DOES NOT EXIST> error.
Examples
The following example shows $CLASSMETHOD used as a function:
SET classname = "%Dictionary.ClassDefinition"
SET classmethodname = "NormalizeClassname"
SET singleargument = "%String"
WRITE $CLASSMETHOD(classname,classmethodname,singleargument),!
It returns %Library.String.
The following example shows $CLASSMETHOD with two arguments:
WRITE $CLASSMETHOD("%Library.Persistent","%PackageName"),!
WRITE $CLASSMETHOD("%Library.Persistent","%ClassName")
These calls return %Library and %Persistent.
The following example uses $CLASSMETHOD to execute a Dynamic SQL query:
SET q1="SELECT Age,Name FROM Sample.Person "
SET q2="WHERE Age > ? AND Age < ? "
SET q3="ORDER by Age"
SET myquery=q1_q2_q3
SET rset=$CLASSMETHOD("%SQL.Statement","%ExecDirect",,myquery,12,20)
DO rset.%Display()
WRITE !,"Teenagers in Sample.Person"