Directives
FUNCTION Declare Object Method
   
Formats
1. Declare Method: FUNCTION [ HIDE ] method [(args)] logic
2. Method with PERFORM Behaviour: FUNCTION [ HIDE ] PERFORM method [(args)] logic
3. Local Method: FUNCTION [ HIDE ] LOCAL method [(args)] logic
4. COM Event Method: FUNCTION method [(args)] logic FOR EVENT {event$|SAME}
5. End Method Declaration: FUNCTION END

Where:

(args) Optional parameter list within parenthesis.
END Keyword indicating the end of a method declaration.
event$ Name of the corresponding COM event.
FOR EVENT Keyword indicating that method is associated with given COM event.
HIDE Keyword indicating that method is not to be displayed in the list of methods returned by '*
LOCAL Keyword indicating that method is only to be called within theobject.
logic Procedure associated with method. Method should return a value; if not, the system forces 0 or " ".
method Name of method that the object can perform. (In Object Oriented
Programming, functions are referred to as methods.)
PERFORM Keyword indicating that logic is to be loaded/executed as in a PERFORM.
SAME Keyword to use if the method name matches event$ name.

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.,

FUNCTION Find(X$) LookupCust
... ... ... LookupCust: ENTER Cst_id$
... ... ... ! Logic to find the client
RETURN sts ! Return value indicates success

Alternatively, the function logic can directly follow the FUNCTION declaration; e.g.,

FUNCTION Find(X$) ENTER Cst_id$
... ... ... ! Logic to find the client
RETURN sts ! Return value indicates success.

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.,

DEF CLASS "MyObj" FUNCTION MyFirstMethod()
a=b, d=f
if ... ... ... etc
FUNCTION MySecondMethod()
a=b, d=f

if ... ... ... etc
FUNCTION END
END DEF

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:

IF NOT(Cst'Find("ABCD")) THEN GOTO Bad_cust.



  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