Methods in Expressions
The 4GL statement, method invocation, lets you invoke a method as part of an expression. For more information about this statement, see
Method Invocation Statement.
When a method returns a value, it can function as an expression. In the following syntax example, methodname is the name of a method that returns a value:
returnval = objectref.methodname() + 1;
When you call a method as part of an expression, you must explicitly name the method. You can use a variable for the name of a method if you assign the name to a varchar variable. For example, the following assignment is legal:
a = objectref.:varmeth();
However you cannot use operators when you are assigning a variable as the method name. For example, the following expression is illegal and cannot be specified at runtime:
a = objectref.:varmeth() + 7;
Because methods can return a value of any type, such as an object or an array, you can operate on the return value with any operation appropriate to the return value type. In this syntax example, methodname is a method that returns a numeric type like integer or float, allowing you to use the return value in the addition.
If a method returns an object, the return value can be manipulated like any other object. That is, you can use the dot operator (.) to access individual attributes, or you can apply a method to that object.
Using the dot operator gets a variable of some kind (depending on the type of the attribute), so you can use the resulting variable wherever other variables can be used. For example, if the addr_meth method returns a variable of class Addr that has an attribute of City, the following expression is legal:
objectref.Addr_meth().City = 'New York';