Advanced features / Globals |
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 must contain the .4gl suffix. It can be a relative or an absolute path. To specify a path, the slash (/) directory separator can be used for UNIX™ and Windows™ platforms.
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 oneGLOBALS 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.
Using global elements is not recommended, prefer to export module elements with the PUBLIC keyword, and include the module into other modules with the IMPORT FGL instruction.