Quick start manual

5-40
Delphi Language Guide
Variables
X and Y are of the same type; at runtime, there is no way to distinguish TValue from
Real. This is usually of little consequence, but if your purpose in defining a new type
is to utilize runtime type information—for example, to associate a property editor
with properties of a particular type—the distinction between “different name” and
“different type” becomes important. In this case, use the syntax
type newTypeName = type type
For example,
type TValue = type Real;
forces the compiler to create a new, distinct type called TValue.
For var parameters, types of formal and actual must be identical. For example,
type
TMyType = type Integer
procedure p(var t:TMyType);
begin end;
procedure x;
var
m: TMyType;
i: Integer;
begin
p(m); //Works
p(i); //Error! Types of formal and actual must be identical.
end;
Note
This only applies to var parameters, not to const or by-value parameters
Variables
A variable is an identifier whose value can change at runtime. Put differently, a
variable is a name for a location in memory; you can use the name to read or write to
the memory location. Variables are like containers for data, and, because they are
typed, they tell the compiler how to interpret the data they hold.
Declaring variables
The basic syntax for a variable declaration is
var identifierList: type;
where identifierList is a comma-delimited list of valid identifiers and type is any valid
type. For example,
var I: Integer;
declares a variable I of type Integer, while
var X, Y: Real;
declares two variables—X and Y—of type Real.