Statement PUBLIC Foundation
PUBLIC-Creates and initializes memory variables.
PUBLIC <VarName> [[:= <Expression>], ... ]
The PUBLIC statement generates variables which belong to the storage class PUBLIC. Storage classes define the lifetime and visibility of variables. With the PUBLIC statement, so called "dynamic" variables are created at runtime. The PUBLIC statement belongs to the executable statements and must follow declarations of MEMVAR, FIELD, LOCAL or STATIC.
The declaration of a PUBLIC variable takes place with the declaration MEMVAR. The creation of such a variable takes place with the statement PUBLIC. Since the symbolic names of PUBLIC variables exist at runtime, they can be saved in files with the SAVE command and can be restored at runtime. PUBLIC variables can also be dynamically created from character string expressions using the macro operator (&) at runtime. This cannot be done with LOCAL or STATIC variables.
The variable name <VarName> may occur only once within a function. This includes variables which are declared as STATIC or as LOCAL. If a PRIVATE or a PUBLIC variable which has the variable name <VarName>already exists in a higher ordered function, the new PUBLIC variable is not created, but the PRIVATE or PUBLIC variable in the higher ordered function or procedure is referenced. That means that PUBLIC variables can be "hidden" by PRIVATE variables, although the reverse is not possible.
The length of a variable name is unlimited, but only the first 255 characters are significant. A variable name consists of alphanumeric characters, and the first character may not be numeric. The underscore (_) is permitted as a special character.
The lifetime of a PUBLIC variable extends implicitly to the entire lifetime of a program. It is released upon program termination, but can also explicitly be deleted with one of the commands CLEAR ALL, CLEAR MEMORY or RELEASE. A PUBLIC variable remains globally visible. It can, if necessary, be "hidden" by a new variable with the same variable name which belongs to the storage class PRIVATE, LOCAL or STATIC. As soon as the "new" variable is no longer visible or no longer exists, the PUBLIC variable becomes visible again.
A PUBLIC variable can be initialized when it is created, meaning the value of any expression may be assigned to it by using the inline assignment operator (:=), or it can be initialized by using the array element operator [] as an array with any dimension or size. If no assignment is done, PUBLIC variables have the value .F. (false) after generation. That is an exception to the rule of the default value being NIL for non-initialized variables. When a PUBLIC variable is initialized as an array, no further assignment is possible and all array elements have the value NIL.
If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.