Quick start manual

5-44
Delphi Language Guide
Declared constants
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;
Constant expressions
A constant expression is an expression that the compiler can evaluate without
executing the program in which it occurs. Constant expressions include numerals;
character strings; true constants; values of enumerated types; the special constants
True, False, and nil; and expressions built exclusively from these elements with
operators, typecasts, and set constructors. Constant expressions cannot include
variables, pointers, or function calls, except calls to the following predefined
functions:
This definition of a constant expression is used in several places in Delphi’s syntax
specification. Constant expressions are required for initializing global variables,
defining subrange types, assigning ordinalities to values in enumerated types,
specifying default parameter values, writing case statements, and declaring both true
and typed constants.
Examples of constant expressions:
100
'A'
256 - 1
(2.5 + 1) / (2.5 - 1)
'Borland' + ' ' + 'Developer'
Chr(32)
Ord('Z') - Ord('A') + 1
Abs
Chr
Hi
High
Length
Lo
Low
Odd
Ord
Pred
Round
SizeOf
Succ
Swap
Trunc