Quick start manual
5-24
Delphi Language Guide
Structured types
Or use a with statement:
with Record1 do
begin
Year := 1904;
Month := Jun;
Day := 16;
end;
You can now copy the values of Record1’s fields to Record2:
Record2 := Record1;
Because the scope of a field designator is limited to the record in which it occurs, you
don’t have to worry about naming conflicts between field designators and other
variables.
Instead of defining record types, you can use the record ... construction directly in
variable declarations:
var S: record
Name: string;
Age: Integer;
end;
However, a declaration like this largely defeats the purpose of records, which is to
avoid repetitive coding of similar groups of variables. Moreover, separately declared
records of this kind will not be assignment-compatible, even if their structures are
identical (See “Assignment-compatibility” on page 5-38).
Variant parts in records
A record type can have a variant part, which looks like a case statement. The variant
part must follow the other fields in the record declaration.
To declare a record type with a variant part, use the following syntax.
type recordTypeName = record
fieldList
1
: type
1
;
ƒ
fieldList
n
: type
n
;
case tag: ordinalType of
constantList
1
: (variant
1
);
ƒ
constantList
n
: (variant
n
);
end;
The first part of the declaration—up to the reserved word case—is the same as that of
a standard record type. The remainder of the declaration—from case to the optional
final semicolon—is called the variant part. In the variant part,
• tag is optional and can be any valid identifier. If you omit tag, omit the colon (:)
after it as well.
• ordinalType denotes an ordinal type.