Rules for globals usage
Follow the rules described in this topic in order to use globals properly.
In order to extend the scope of variables,
constants or user types to the whole program, define a module containing a GLOBALS ... END
GLOBALS
block and including this global module with the GLOBALS
"filename"
statement in other modules.
The filename should contain the .4gl
suffix. However, the
compiler uses the file name as it is. Therefore it can accept other file extensions such as
GLOBALS "stock.glb"
.
GLOBALS
defines a relative file path, the globals file will be
searched relatively to the current directory when executing fglcomp. As a general
rule, execute fglcomp in the directory of the source file passed as
argument.If you modify the globals file, you must recompile all the modules that include the file.
If a local element has the same name as another variable that you
declare in the GLOBALS
statement, only the local
variable is visible within its scope of reference.
You can declare several GLOBALS .. END GLOBALS
blocks
in the same module.
A GLOBALS
file must not contain any executable
statement.
Do not write a declaration statement outside a GLOBALS
... END GLOBALS
block in a GLOBALS
file.
You do not need to compile the source file containing the GLOBALS
block.
However, it is recommended to compile the globals file to detect errors.
You can declare several GLOBALS "filename"
instructions in
the same module.
Although you can include multiple GLOBALS ... END GLOBALS
statements
in the same application, do not declare the same identifier within
more than one GLOBALS
declaration. Even if several
declarations of a global elements defined in multiple places are identical,
declaring any global element more than once can result in compilation
errors or unpredictable runtime behavior.
A GLOBALS
block can hold GLOBALS "filename"
instructions. In such case, the specified files will be included recursively.
PUBLIC
keyword, and include the module in other modules with the IMPORT FGL
instruction.