Language Reference Guide : 2. Language Elements : Expressions : Procedures in Expressions
 
Share this page                  
Procedures in Expressions
When a procedure returns a value, such as a return code, it functions as an expression. In the following syntax example, procname is the name of a procedure that returns a value:
returnval = procname() + 1;
When you call a procedure as part of an expression, the following rules apply:
Do not use the callproc keyword.
Include the parentheses even if you are not passing any parameters to the procedure.
Explicitly name the procedure. You can use a variable for the name of a procedure if you assign it to a variable. For example, the following assignment is legal:
a = :varproc();
However you cannot use operators when you are assigning a variable as the procedure name. For example, the following expression is illegal and cannot be specified at runtime:
a = :varproc() + 7;
Because procedures 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 the syntax example just described, procname is a procedure that returns a numeric type like integer or float, allowing you to use the return value in the addition.
If a procedure 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 produces 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_proc procedure returns a variable of class Addr that has an attribute “City,” the following expression is legal:
addr_proc().City = 'New York';
Because you can apply methods to the return value, and because methods can return values of any type, referencing can be nested on a procedure's return value, for example:
ret_framexec().ObjectSource.Duplicate().name