Variables are explicitly named memory locations with a certain type. When assigning values to
variables, the Free Pascal compiler generates machine code to move the value to the memory
location reserved for this variable. Where this variable is stored depends on where it is
declared:
- Global variables are variables declared in a unit or program, but not inside a procedure
or function. They are stored in xed memory locations, and are available during the
whole execution time of the program.
- Local variables are declared inside a procedure or function. Their value is stored on
the program stack, i.e. not at xed locations.
The Free Pascal compiler handles the allocation of these memory locations transparantly, although
this location can be in uenced in the declaration.
The Free Pascal compiler also handles reading values from or writing values to the variables
transparantly. But even this can be explicitly handled by the programmer when using
properties.
Variables must be explicitly declared when they are needed. No memory is allocated unless a
variable is declared. Using an variable identi er (for instance, a loop variable) which is not declared
rst, is an error which will be reported by the compiler.