Important Notice
The pages on this site contain documentation for very old MS-DOS software,
purely for historical purposes.
If you're looking for up-to-date documentation, particularly for programming,
you should not rely on the information found here, as it will be woefully
out of date.
CONST Declaration Section
◄Keywords► ◄Contents► ◄Index► ◄Back►
CONST <identifier> [ : <type> ] = <constant expression>;
.
.
<identifier> [ : <type> ] = <constant expression>;
Description
CONST starts a program section that defines constants and typed
constants. Constants are named values that cannot be modified. Typed
constants, sometimes called variable constants, are initialized to a
value and can be used as variables.
The value assigned to a constant identifier can be a constant value
or a constant expression. A constant expression is evaluated by the
compiler. The expression may contain other constants, but must not
contain typed constants or variables. It may not use the address
operator (@), and may use only the following functions:
Abs ║ Last ║ Ord ║ SizeOf
Chr ║ Length ║ Pred ║ Succ
First ║ Lo ║ Ptr ║ Swap
Hi ║ Odd ║ Round ║ Trunc
A typed constant may be used instead of a variable initialized in
the program block. A typed constant declared in a procedure or
function is initialized once at the start of the program, and its
current value is preserved between calls to the procedure or
function. The syntax for declaring a simple typed constant of a
type is illustrated at the top of the screen. Other types of typed
constants are:
CONST
string_example : STRING[11] = 'String text';
array_example : ARRAY[0..2] OF Char = ( 'A', 'B', 'C' );
packed_example : ARRAY[0..2] OF Char = 'ABC' ;
nested_example : ARRAY[0..2, 0..2] OF Byte
= ((1,0,0),(0,1,0),(0,0,1));
record_example : DateTime = ( Year : 2001; Month : 1; Day : 1;
Hour : 0; Min : 0; Sec : 1 );
set_example : SET OF 'A'..'Z' = [ 'A', 'E', 'I', 'O', 'U' ];
All elements of arrays and all fields of records must be given a
value. Pointer typed constants can be initialized only to NIL.
See also: LABEL, TYPE, VAR