Name

Integer Type

Syntax

type Integer = -2147483648..2147483647;

Description

The Integer type is the basic integer type. The size of an integer can vary with different versions of Delphi. Currently, Integer is a 32-bit type, but future versions might change the size.

Delphi defines a number of integer types of varying ranges. The predefined integer types are shown in the following table.

Type

Minimum

Maximum

Byte

0

255

ShortInt

-128

127

Word

0

65,535

SmallInt

-32,768

32,767

LongWord

0

4,294,967,295

LongInt

-2,147,483,648

2,147,483,647

Integer

natural

natural

Cardinal

0

natural

Int64

-9,223,372,036,854,775,808

9,223,372,036,854,775,807

Tips and Tricks

  • Numeric constants are type Integer if they fall within the range of Integer; otherwise, they are of type Int64. Arithmetic expressions with at least one argument of type Int64 yield a result of type Int64. If both arguments are integer types, the result type is Integer.

  • The size of the Cardinal and Integer types can change from one release of Delphi to another. In Delphi 5, both are 32 bits, but a future version of Delphi will undoubtedly change the size to 64 bits.

  • Whenever possible, you should use an explicit subrange. If you know that a value will always be positive, for example, declare the variable accordingly. The additional type safety helps catch mistakes (where you accidentally assign a nonpositive number to the variable), and it helps to document the program by giving the reader additional information ...

Get Delphi in a Nutshell 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.