Do method

Command group Flag affected Reversible Execute on client Platform(s)
Methods NO NO YES All

Syntax

Do method method-name (parameters) Returns return-value

Description

This command runs the specified method in the current class, and accepts a value back from the called method. If you use the Do method command in a field or line method, Omnis searches for the specified method in the field or line methods for the class, and then searches in the class methods. If the specified method is not found there is an error.

The command accepts a value back from the recipient or receiving method if you specify a return-value, which can be a variable of any type. Note that where the return field is an item reference, the command sets the reference but does not assign to it: you must do this with Calculate or Do Itemref.$assign(value).

When another method is executed using this command, control is passed to the called method. When the called method has executed, control passes back to the original executing method. Note that you should use Do code method if you want to run a method in a code class, that is, a method outside the current class.

Passing Parameters

You can include a list of parameters with Do method which are passed to the called method. The parameters are taken in the order they appear in the parameter list and placed in the parameter variables in the called method. You can pass a reference to a field by using the special parameter variable type Field reference. This means that the called method can make changes to the field passed to it.

Recursion

Omnis allows a method to call itself, but will eventually run out of stack if the recursion does not terminate, or becomes too deep.

Example

# Call the method myMethod in the current instance which
# returns a value into iMyVar using Quit method lReturnValue
Do method myMethod Returns iMyVar
# Call myMethod and pass the field reference iMyFieldRef
# so that the value of iMyFieldRef can be changed by the
# method called
Calculate iMyFieldRef as 10
Do method myMethod (iMyFieldRef)
# You can use $cinst, $cfield, and $ctask to specify a method
# in the current instance, field, or task.
Do method $cinst.$mymethod
Do method $cfield.$myfieldmethod
Do method $ctask.$mytaskmethod
# You can also use the do command to call a method
Do $cinst.$mymethod