const
The Const keyword is used to start a section of constant definitions.
The section is terminated by the next keyword in a program. Within the section,
one or more constants may be defined. These can be a mixture of normal or typed
constants or expressions.
When passing data to a routine (function or procedure), you can prefix the parameter
definition with Const if the value is never updated within the called routine. This
improves performance, clarifies routine operation, and prevents accidental updates
of the value.
Example
Download This Source for Free Pascal
Const
MAX_LINES = 3;
CRUDE_PI = 22/7;
HELLO = 'Hello World';
LETTERS = ['A'..'Z', 'a'..'z'];
DECISION = True;
var
i : Integer;
begin
// Display our crude value of Pi
Writeln('Crude Pi = ',CRUDE_PI);
// Say hello to the WOrld
Writeln(HELLO);
// Display MAX_LINES of data
for i := 1 to MAX_LINES do begin
// Do some checking - note that Char(i+64) = 'A'
if DECISION and (Char(i+63) in LETTERS)
then Writeln(Char(i+63),' is a letter')
else Writeln(Char(i+63),' is not a letter');
end;
end.
Output
Crude Pi = 3.1428571428571429E+0000
Hello World
@ is not a letter
A is a letter
B is a letter
See Also
Function,
Out,
Procedure,
Type,
Var.