Indexes
Strings, arrays, array properties, and pointers to strings or arrays can be indexed. For example, if
FileName
is a
string variable, the expression
FileName[3]
returns the third character in the string denoted by
FileName
, while
FileName[I + 1]
returns the character immediately after the one indexed by
I
. For information about strings,
see String types. For information about arrays and array properties, see Arrays and Array properties.
Typecasts
It is sometimes useful to treat an expression as if it belonged to different type. A typecast allows you to do this by,
in effect, temporarily changing an expression's type. For example,
Integer('A')
casts the character
A
as an
integer.
The syntax for a typecast is
typeIdentifier(expression)
If the expression is a variable, the result is called a variable typecast; otherwise, the result is a value typecast. While
their syntax is the same, different rules apply to the two kinds of typecast.
Value Typecasts
In a value typecast, the type identifier and the cast expression must both be ordinal or pointer types. Examples of
value typecasts include
Integer('A')
Char(48)
Boolean(0)
Color(2)
Longint(@Buffer)
The resulting value is obtained by converting the expression in parentheses. This may involve truncation or extension
if the size of the specified type differs from that of the expression. The expression's sign is always preserved.
The statement
I := Integer('A');
assigns the value of
Integer('A')
, which is 65, to the variable
I
.
A value typecast cannot be followed by qualifiers and cannot appear on the left side of an assignment statement.
Dostları ilə paylaş: