Declared Constants Several different language constructions are referred to as 'constants'. There are numeric constants (also called
numerals) like 17, and string constants (also called character strings or string literals) like 'Hello world!'. Every
enumerated type defines constants that represent the values of that type. There are predefined constants like True,
False, and nil. Finally, there are constants that, like variables, are created individually by declaration.
Declared constants are either true constants or typed constants. These two kinds of constant are superficially similar,
but they are governed by different rules and used for different purposes.
True Constants A true constant is a declared identifier whose value cannot change. For example,
const MaxValue = 237;
declares a constant called
MaxValue
that returns the integer 237. The syntax for declaring a true constant is
const identifier = constantExpression where identifier is any valid identifier and constantExpression is an expression that the compiler can evaluate without
executing your program.
If constantExpression returns an ordinal value, you can specify the type of the declared constant using a value
typecast. For example
const MyNumber = Int64(17);
declares a constant called
MyNumber
, of type Int64, that returns the integer 17. Otherwise, the type of the declared
constant is the type of the constantExpression.
If constantExpression is a character string, the declared constant is compatible with any string type. If the
character string is of length 1, it is also compatible with any character type.
If constantExpression is a real, its type is Extended. If it is an integer, its type is given by the table below.