HDevelop supports local and global variables. All variables are local by default. They exist only within their procedure. Local variables with the same name may exist in different procedures without interfering with each other. In contrast, global variables may be accessed in the entire program. They have to be declared explicitly using the global statement.
When using HDevEngine, a global variable can extend beyond the scope of its program
as HDevEngine manages the variables of all loaded programs and procedures.
This can be used to transfer information between procedures.
Each global variable can have only one value at a time for all procedure calls of the running HDevEngine instance.
Therefore, take care not to overwrite the value of a variable of one program with that of another.
For more information about HDevEngine, see the 程序员指南.
The declaration
global tuple File
declares a global control variable named File, whereas
global object Image
declares a global iconic variable Image.
The keyword def allows you to mark one declaration explicitly as the place where the variable is defined, for example, global def object Image. This is only relevant when exporting the program to a programming language. See the description of the operator global for more information.
Once the global variable is declared, it can be used just like a local variable inside the procedure it has been declared in. If you want to access a global variable in a different procedure, you have to announce this by using the same global ... call (otherwise, a local variable will be created).
main procedure: * declare global variables global tuple File global object Image ... File := 'particle' read_image(Image, File) process_image() * Image has been changed by process_image() * File remains unchanged ... process_image procedure: * use global variable global object Image ... bin_threshold(Image, Region) File := 'fuse' read_image(Image, File) return()
Procedures have to explicitly announce their use of global variables, existing procedures cannot be broken by introducing global variables in other parts of the program. By nature, the names of global variables have to be unique in the entire HDevelop program. The variable window provides a special tab to list all global variables that are currently declared.