Invoking a Class Method
To invoke a class method, the syntax is either of the following:
>Do ##class(Package.Class).Method(Args)
>Set localname = ##class(Package.Class).Method(Args)
It is also valid to use ##class as part of an expression, as in
Write ##class(Class).Method(args)*2
without setting a variable equal to the return value.
A frequent use of this syntax is in the creation of new instances:
>Set LocalInstance = ##class(Package.Class).%New()
Casting a Method
To cast a method of one class as a method of another class, the syntax is either of the following:
>Do ##class(Package.Class1)Class2Instance.Method(Args)
>Set localname = ##class(Package.Class1)Class2Instance.Method(Args)
You can cast both class methods and instance methods.
For example, suppose that two classes, MyClass.Up and MyClass.Down, both have Go() methods. For MyClass.Up, this method is as follows
Method Go()
{
Write "Go up.",!
}
For MyClass.Down, the Go() method is as follows:
Method Go()
{
Write "Go down.",!
}
You can then create an instance of MyClass.Up and use it to invoke the MyClass.Down.Go method:
>Set LocalInstance = ##class(MyClass.Up).%New()
>Do ##class(MyClass.Down)LocalInstance.Go()
Go down.
It is also valid to use ##class as part of an expression, as in
Write ##class(Class).Method(args)*2
without setting a variable equal to the return value.
A more generic way to refer to other methods are the $METHOD and $CLASSMETHOD functions, which are for instance and class methods, respectively; these are described in Dynamically Accessing Objects. These provide a mechanism for referring to packages, classes, and methods programmatically.
Accessing a Class Parameter
To access a class parameter, you can use the following expression:
##class(Package.Class).#PARMNAME
Where Package.Class is the name of the class and PARMNAME is the name of the parameter. For example:
w ##class(%XML.Adaptor).#XMLENABLED
displays whether methods generated by the XML adaptor are XML enabledOpens in a new tab, which by default is set to 1.
You can also use the $PARAMETER functions, which is described in Dynamically Accessing Objects.