If an EGL part declares a variable or constant, the identifier used in
the declaration is
in scope (available) throughout the part:
- If the declaration is in a function, the identifier is in the local scope
of the function. If the function Function01 declares the variable Var01, for
example, any code in Function01 can reference Var01. The identifier is available
even in function code that precedes the declaration.
The variable can be
passed as an argument to another function, but the original identifier is
not available in that function. The parameter name is available in the receiving
function because the parameter name was declared there.
- If the declaration is in a generatable part such as a program but is outside
of any function, the identifier is in program-global scope, which means
that the identifier can be referenced by any function invoked by that part.
For example, if a program declares Var01 and invokes Function01 which in turn
invokes Function02, Var01 is available throughout both functions.
The identifiers
in a text or print form are global to the generatable part that references
the form. Those identifiers are available even in functions that precede the
function which presents the form.
- If the declaration is in a library but outside of any function, the identifier
is in run-unit scope, which means global to all code in the run unit.
- The names of a dataTable and its fields may be in program-global, run-unit,
or an even larger scope, depending on the setting of dataTable properties
and on the environment in which the dataTable resides.
Identifiers that are identical cannot be in the same scope. However, most
identifiers refer to an area of memory that is logically inside a container
such as a record; and in those cases your code qualifies an identifier with
the name of the enclosing container. If the function variable myString is
in a record called myRecord01, for example, your code refers to the variable
as a field of the record:
myRecord01.myString
If the same identifier is in two scopes, any reference to the identifier
is a reference to the most local scope, but you can use qualifiers to override
that behavior:
- Consider the case of a program that declares variable Var01 and invokes
a function that itself declares a variable of the same name. An unqualified
reference to Var01 in the function causes access of the locally declared variable.
To
access an identifier that is program-global even when a local identifier takes
precedence, qualify the identifier with the keyword
this,
as in the following example:
this.Var01
In rare cases the keyword this is
also used to override a behavior of a set value block in an assignment statement.
For details, see Set value blocks.
- Consider the following case--
- A program has a use declaration to access a library; and
- The program and the library each declare a variable named Var01.
If a function in the program includes an unqualified reference to
Var01, the function accesses the program variable.
To access an identifier
in run-unit scope even when another identifier prevents that access, qualify
the identifier with the part name, as in the following example (where myLib
is the name of a library):
myLib.Var01
If the
library or dataTable is in a different package and you have not referenced
the part in an import statement, you must preface the part name with the package
name, as in the following example (where myPkg is the package name):
myPkg.myLib.Var01
The
package name always qualifies a part name and cannot immediately precede a
variable or constant identifier.
Finally, a local identifier may be
the same as a dataTable or library name if the local identifier is in a different
package from where the dataTable or library resides. To reference the dataTable
or library name, include the package name.