Quick start manual
Data types, variables, and constants
5-1
Chapter
5
Chapter5
Data types, variables, and constants
A type is essentially a name for a kind of data. When you declare a variable you must
specify its type, which determines the set of values the variable can hold and the
operations that can be performed on it. Every expression returns data of a particular
type, as does every function. Most functions and procedures require parameters of
specific types.
The Delphi language is a “strongly typed” language, which means that it
distinguishes a variety of data types and does not always allow you to substitute one
type for another. This is usually beneficial because it lets the compiler treat data
intelligently and validate your code more thoroughly, preventing hard-to-diagnose
runtime errors. When you need greater flexibility, however, there are mechanisms to
circumvent strong typing. These include typecasting (see “Typecasts” on page 4-15),
pointers (see “Pointers and pointer types” on page 5-27), variants (see “Variant types”
on page 5-33), variant parts in records (see “Variant parts in records” on page 5-24),
and absolute addressing of variables (see “Absolute addresses” on page 5-41).
About types
There are several ways to categorize Delphi data types:
• Some types are predefined (or built-in); the compiler recognizes these automatically,
without the need for a declaration. Almost all of the types documented in this
language reference are predefined. Other types are created by declaration; these
include user-defined types and the types defined in the product libraries.
• Types can be classified as either fundamental or generic. The range and format of a
fundamental type is the same in all implementations of the Delphi language,
regardless of the underlying CPU and operating system. The range and format of
a generic type is platform-specific and could vary across different
implementations. Most predefined types are fundamental, but a handful of
integer, character, string, and pointer types are generic. It’s a good idea to use
generic types when possible, since they provide optimal performance and