Constants

Constants in Pascal are defined in a const clause, which behaves similarly to the C/C++'s const keyword. Here's an example of three constant declarations in C:

const float ADecimalNumber = 3.14;
const int i = 10;
const char * ErrorString = "Danger, Danger, Danger!";

The major difference between C constants and Object Pascal constants is that Object Pascal, like Visual Basic, doesn't require you to declare the constant's type along with the value in the declaration. The Delphi compiler automatically allocates proper space 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:

 const ADecimalNumber ...

Get Borland® Delphi™ 6 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.