Next: 2.2 Typed constants
Up: 2. Constants
Previous: 2. Constants
Ordinary constants declarations are no different from the Turbo Pascal or
Delphi implementation.
Constant declaration
The compiler must be able to evaluate the expression in a constant
declaration at compile time. This means that most of the functions
in the Run-Time library cannot be used in a constant declaration.
Operators such as +, -, *, /, not, and, or, div(), mod(), ord(), chr(),
sizeof can be used, however. For more information on expressions,
You can only declare constants of the following types: Ordinal types,
Real types, Char, and String.
The following are all valid constant declarations:
Const
e = 2.7182818; { Real type constant. }
a = 2; { Integer type constant. }
c = '4'; { Character type constant. }
s = 'This is a constant string'; {String type constant.}
s = chr(32)
ls = SizeOf(Longint);
Assigning a value to a constant is not permitted. Thus, given the previous
declaration, the following will result in a compiler error:
s := 'some other string';
root
1999-06-10