Delphi Language Guide Delphi for Microsoft Win32 Delphi for the Microsoft. Net framework



Yüklə 0,84 Mb.
Pdf görüntüsü
səhifə71/294
tarix02.01.2022
ölçüsü0,84 Mb.
#41395
1   ...   67   68   69   70   71   72   73   74   ...   294
DelphiLanguageGuide

Set Constructors
A set constructor denotes a set-type value. For example,
[5, 6, 7, 8]
denotes the set whose members are 5, 6, 7, and 8. The set constructor
[ 5..8 ]
could also denote the same set.
The syntax for a set constructor is
[ item1, ..., itemn ]
where each item is either an expression denoting an ordinal of the set's base type or a pair of such expressions with
two dots (..) in between. When an item has the form 
x..y
, it is shorthand for all the ordinals in the range from 
x
to 
y
, including 
y
; but if 
x
 is greater than 
y
, then 
x..y
, the set
 [x..y]
, denotes nothing and is the empty set. The
set constructor 
[ ]
 denotes the empty set, while 
[x]
 denotes the set whose only member is the value of 
x
.
Examples of set constructors:
[red, green, MyColor]
[1, 5, 10..K mod 12, 23]
['A'..'Z', 'a'..'z', Chr(Digit + 48)]
For more information about sets, see Sets.
55


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.

Yüklə 0,84 Mb.

Dostları ilə paylaş:
1   ...   67   68   69   70   71   72   73   74   ...   294




Verilənlər bazası müəlliflik hüququ ilə müdafiə olunur ©azkurs.org 2024
rəhbərliyinə müraciət

gir | qeydiyyatdan keç
    Ana səhifə


yükləyin