| Directives |
|
| Formats |
The HIDE option is a +PxPlus Exclusive (build 9182) |
||||||||||||||||||||||||||||||||
| Description | The
FUNCTION directive is used to declare a
method for an object in Object Oriented
Programming (OOP). Each method must have
associated logic that will be called when it is invoked;
e.g.,
Alternatively, the function logic can directly follow the FUNCTION declaration; e.g.,
The declaration ends with a FUNCTION END directive for the method itself, by the start of the next method declaration, or when END DEF is reached at the end of the object definition; e.g.,
Every method should return a value. The value can take the form of a string or numeric value depending on the name associated with the function (string functions must end with $). If no RETURN value is specified, then the system will return a value of zero for numeric functions and "" (null) for string functions. |
||||||||||||||||||||||||||||||||
| *Note* | As
a general rule of thumb, methods should return a non-zero
value when successfully executed. This allows for logic
such as:
|
||||||||||||||||||||||||||||||||
| When
arguments are used in the definition, then the
type/number should normally match variables in the
application code. Multiple definitions of the same method
name can be specified, as long as each method has a
different parameter list. In order to determine which
method to actually use, ProvideX attempts to match up the
parameter lists specified with the variables provided in
the application. If an asterisk * is used in the definition in place of the argument list (e.g., FUNCTION readbykey(*)), the method will be invoked regardless of the type/number of variables to be matched in the corresponding logic. FUNCTION PERFORM indicates that the function logic is to be loaded and executed (as in a PERFORM directive). All variables will be shared with the calling program. |
|||||||||||||||||||||||||||||||||
| *Note* | The PERFORM format violates the general rules of OOP encapsulation. | ||||||||||||||||||||||||||||||||
| FUNCTION LOCAL indicates that the function is only to be called internally from within the object. It cannot be called externally. | |||||||||||||||||||||||||||||||||
| Examples | FUNCTION
Find(X$) LookupByName FUNCTION Find(X) LookupByNumber ... ... ... LookupByName: ENTER Cst_id$ ... ... ... ! Logic to find the client by name RETURN ... LookupByNumber: ENTER Cst_id ... ... ... ! Logic to find the client by number RETURN ... |
||||||||||||||||||||||||||||||||
| See Also | Object
Oriented Programming DEF CLASS Define Object Class ON EVENT Event Processing |
||||||||||||||||||||||||||||||||