Node:const, Next:constructor, Previous:Conjugate, Up:Reference
(Under construction.)
Constant declaration or constant parameter declaration.
const is defined in ISO 7185 Pascal and supported by all
known Pascal variants. const parameters are a Borland Pascal
extension. Pointers to const are a GNU Pascal extension.
Constant declarations allow you to define names for constant (unchanging)
values, such as using SecondsPerHour instead of 3600. This can make
your program much more readable and maintainable.
GNU Pascal allows you to define constant strings, records and arrays as well as simple numeric constants.
GNU Pascal also implements the const parameter extension which allows the compiler to pass parameters by reference while still allowing you to pass constant values as inputs. See Subroutine Parameter List Declaration for more information.
@@ Pointers to const @@
program ConstDemo;
type
Rec = record
x: Integer;
y: Integer;
end;
const
a = 5;
constr: Rec = (10, 12);
procedure doit (const r: Rec; const s: String);
begin
WriteLn (r.x);
WriteLn (r.y);
WriteLn (s);
end;
var
variabler: Rec;
begin
variabler.x := 16;
variabler.y := 7;
doit (variabler, 'Should be 16 and 7');
doit (constr, 'Should be 10 and 12');
end.