PUBLIC

Top  Previous  Next

 

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

 

varis a simple scalar variable. The variable name may be followed by READONLY to indicate that external references to the variable may not update it.

 

mat(rows, cols)is a dimensioned matrix name. The rows and cols values must be numeric constants. The dimension values may be followed by READONLY to indicate that external references to the variable may not update it.

 

name(arg1, arg2)is the subroutine or function name and an optional list of arguments. See the CLASS statement for the maximum number of arguments allowed in this list. Specifying the final argument name as three periods (...) effectively extends the argument list to the maximum permissible length with unnamed arguments that may be accessed using the ARG() function. Use of this syntax automatically implies the VAR.ARGS option which must not also be present.

 

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