Name
$WriteableConst Compiler Directive
Syntax
{$J+} // default
{$WriteableConst On} // default
{$J-}
{$WriteableConst Off}Scope
Local
Description
When
you declare a const with a type, Delphi allocates
memory for the constant. The program can change the value of the
“constant,” just as though it were a variable. The
difference between a typed constant and a local variable is that a
typed constant in a subroutine keeps its value across subroutine
calls.
If you disable the $WriteableConst directive, you
can prevent any assignments to a typed constant, thereby making the
constant truly constant. There is no substitute for typed constants
in a subroutine, though, so disable
$WriteableConst with care. Disable only specific
constants whose value you want to protect, and do not disable this
directive globally in a project or an entire file.
const
{$WriteableConst off}
BoolNames: array[Boolean] of string = ('No way', 'As you wish');
{$WriteableConst on}See Also
| Const Keyword |
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access