PUBLIC |
![]() ![]() ![]() |
The PUBLIC statement defines public property variables, subroutines and functions in a class module.
Format
PUBLIC var, mat(rows, cols), ...
PUBLIC SUBROUTINE name{(arg1, arg2)} {VAR.ARGS} ...statements... END
PUBLIC FUNCTION name{(arg1, arg2)} {VAR.ARGS} ...statements... END
where
Note that the equivalence of a function to a subroutine with a hidden first argument as found with the SUBROUTINE and FUNCTION statements does not apply to public subroutines and functions.
Examples
PUBLIC FUNCTION CONNECT(SERVER, PORT) SKT = OPEN.SOCKET(SERVER, PORT, SKT$BLOCKING) RETURN STATUS() = 0 END
The above function takes a fixed length list of two arguments and uses the supplied values to open a socket connection to a remote server. The SKT variable in this example would be a private variable within the class module.
PUBLIC FUNCTION CONNECT(SERVER, PORT) VAR.ARGS IF UNASSIGNED(PORT) THEN PORT = 4000 SKT = OPEN.SOCKET(SERVER, PORT, SKT$BLOCKING) RETURN STATUS() = 0 END
This example extends the previous one by making the PORT argument optional and, if it is not supplied by the caller, defaulting it to 4000.
PUBLIC SUBROUTINE INSERT.ITEMS(ID, ...) READU REC FROM FVAR, ID ELSE NULL FOR I = 2 TO ARG.COUNT() VALUE = ARG(I) LOCATE VALUE IN REC<1> BY 'AL' SETTING POS ELSE INS VALUE BEFORE REC<POS> END NEXT I WRITE REC TO FVAR, ID END
This example uses the ... syntax to specify a variable length argument list of the maximum permissible length. It reads a record identified by the ID argument and then inserts all items from the remaining arguments that are not already in the record.
See also: Object oriented programming, CLASS, DISINHERIT, INHERIT, OBJECT(), PRIVATE |