Quick start manual

Data types, variables, and constants
5-37
Type compatibility and identity
When you assign a Variant that contains custom data (such as a Delphi string, or a
one of the new custom variant types) to an OleVariant, the runtime library tries to
convert the Variant into one of the OleVariant standard data types (such as a Delphi
string converts to an OLE BSTR string). For example, if a variant containing an
AnsiString is assigned to an OleVariant, the AnsiString becomes a WideString. The
same is true when passing a Variant to an OleVariant function parameter.
Type compatibility and identity
To understand which operations can be performed on which expressions, we need to
distinguish several kinds of compatibility among types and values. These include
type identity, type compatibility, and assignment-compatibility.
Type identity
Type identity is almost straightforward. When one type identifier is declared using
another type identifier, without qualification, they denote the same type. Thus, given
the declarations
type
T1 = Integer;
T2 = T1;
T3 = Integer;
T4 = T2;
T1, T2, T3, T4, and Integer all denote the same type. To create distinct types, repeat the
word type in the declaration. For example,
type TMyInteger = type Integer;
creates a new type called TMyInteger which is not identical to Integer.
Language constructions that function as type names denote a different type each time
they occur. Thus the declarations
type
TS1 = set of Char;
TS2 = set of Char;
create two distinct types, TS1 and TS2. Similarly, the variable declarations
var
S1: string[10];
S2: string[10];
create two variables of distinct types. To create variables of the same type, use
var S1, S2: string[10];
or
type MyString = string[10];
var
S1: MyString;
S2: MyString;