136
FUNCTION Directive
Declare Object Method
Formats
1. Declare Method: FUNCTION method(args) logic
2. Method with PERFORM Behaviour: FUNCTION PERFORM method(args) logic
3. Local Method: FUNCTION 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 list of arguments to be used in the logic when the method is
actually invoked. Parentheses are required with/without arguments.
END
Keyword indicating the end of a method declaration.
event$
Name of the corresponding COM event.
FOR EVENT Keywords indicating that method is associated with given COM event.
LOCAL
Keyword indicating that method is only to be called within the object.
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.
Description
The FUNCTION directive is used to declare a method for an object in Object Oriented
Programming (OOP). Associated logic is to be called when the method 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