To understand which operations can be performed on which expressions, we need to distinguish several kinds of compatibility among types and values. These include:
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; S2: string;
create two variables of distinct types. To create variables of the same type, use
var S1, S2: string;
type MyString = string; var S1: MyString; S2: MyString;
Every type is compatible with itself. Two distinct types are compatible if they satisfy at least one of the following conditions.
Assignment-compatibility is not a symmetric relation. An expression of type T2 can be assigned to a variable of type T1 if the value of the expression falls in the range of T1 and at least one of the following conditions is satisfied.
Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
What do you think about this topic? Send feedback!