Constants

Constants in Delphi are defined in a const clause, which behaves similarly to the C#’s const keyword. Here’s an example of three constant declarations in C#:

public const float ADecimalNumber = 3.14;

public const int i = 10;

public const String ErrorString = "Danger, Danger, Danger!";

The major difference between C# constants and Delphi language constants is that Delphi, like Visual Basic .NET, doesn’t require you to declare the constant’s type along with the value in the declaration. The Delphi compiler automatically allocates the appropriate type for the constant based on its value, or, in the case of scalar constants such as Integer, the compiler keeps track of the values as it works, and space never is allocated. Here’s an example: ...

Get Delphi for .NET Developer’s Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.