True constants | Previous Top Next

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. (See Constant expressions for more information.)
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.
Range of constant(hexadecimal) Range of constant(decimal) Type
–$8000000000000000..–$80000001 –2^63..–2147483649 Int64
–$80000000..–$8001 –2147483648..–32769 Integer
–$8000..–$81 –32768..–129 Smallint
–$80..–1 –128..–1 Shortint
0..$7F 0..127 0..127
$80..$FF 128..255 Byte
$0100..$7FFF 256..32767 0..32767
$8000..$FFFF 32768..65535 Word
$10000..$7FFFFFFF 65536..2147483647 0..2147483647
$80000000..$FFFFFFFF 2147483648..4294967295 Cardinal
$100000000..$7FFFFFFFFFFFFFFF 4294967296..2^63–1 Int64
Here are some examples of constant declarations:
const
Min = 0;
Max = 100;
Center = (Max - Min) div 2;
Beta = Chr(225);
NumChars = Ord('Z') - Ord('A') + 1;
Message = 'Out of memory';
ErrStr = ' Error: ' + Message + '. ';
ErrPos = 80 - Length(ErrStr) div 2;
Ln10 = 2.302585092994045684;
Ln10R = 1 / Ln10;
Numeric = ['0'..'9'];
Alpha = ['A'..'Z', 'a'..'z'];
AlphaNum = Alpha + Numeric;