var X: Size;
X := Small; // Ord(X) = 5
Y := Size(6); // Ord(X) = 6
Inc(X); // Ord(X) = 7
Any value that isn't explicitly assigned an ordinality has ordinality one greater than that of the previous value in the
list. If the first value isn't assigned an ordinality, its ordinality is 0. Hence, given the declaration
type SomeEnum = (e1, e2, e3 = 1);
SomeEnum
has only two possible values:
Ord(e1)
returns 0,
Ord(e2)
returns 1, and
Ord(e3)
also returns 1;
because
e2
and
e3
have the same ordinality, they represent the same value.
Enumerated constants without a specific value have RTTI:
type SomeEnum = (e1, e2, e3);
whereas enumerated constants with a specific value, such as the following, do not have RTTI:
type SomeEnum = (e1 = 1, e2 = 2, e3 = 3);
Dostları ilə paylaş: