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ə70/294
tarix02.01.2022
ölçüsü0,84 Mb.
#41395
1   ...   66   67   68   69   70   71   72   73   ...   294
DelphiLanguageGuide

Note:
When using the @ operator, it is not possible to take the address of an interface method as the address is
not known at compile time and cannot be extracted at runtime.
Operator Precedence
In complex expressions, rules of precedence determine the order in which operations are performed.
Precedence of operators
Operators
Precedence
@, not
first (highest)
*/, div, mod, and, shl, shr, as second
+-, or, xor
third
=<><><=>=, in, is
fourth (lowest)
An operator with higher precedence is evaluated before an operator with lower precedence, while operators of equal
precedence associate to the left. Hence the expression
X + Y * Z
multiplies 
Y
 times 
Z
, then adds 
X
 to the result; * is performed first, because is has a higher precedence than +. But
X - Y + Z
first subtracts 
Y
 from 
X
, then adds 
Z
 to the result; - and + have the same precedence, so the operation on the left is
performed first.
You can use parentheses to override these precedence rules. An expression within parentheses is evaluated first,
then treated as a single operand. For example,
(X + Y) * Z
multiplies 
Z
 times the sum of 
X
 and 
Y
.
Parentheses are sometimes needed in situations where, at first glance, they seem not to be. For example, consider
the expression
X = Y or X = Z
The intended interpretation of this is obviously
(X = Y) or (X = Z)
Without parentheses, however, the compiler follows operator precedence rules and reads it as
(X = (Y or X)) = Z
which results in a compilation error unless 
Z
 is Boolean.
Parentheses often make code easier to write and to read, even when they are, strictly speaking, superfluous. Thus
the first example could be written as
54


X + (Y * Z)
Here the parentheses are unnecessary (to the compiler), but they spare both programmer and reader from having
to think about operator precedence.
Function Calls
Because functions return a value, function calls are expressions. For example, if you've defined a function called
Calc
 that takes two integer arguments and returns an integer, then the function call 
Calc(24,47)
 is an integer
expression. If 
I
 and 
J
 are integer variables, then 
I + Calc(J,8)
 is also an integer expression. Examples of
function calls include
Sum(A, 63)
Maximum(147, J)
Sin(X + Y)
Eof(F)
Volume(Radius, Height)
GetValue
TSomeObject.SomeMethod(I,J);
For more information about functions, see Procedures and functions.

Yüklə 0,84 Mb.

Dostları ilə paylaş:
1   ...   66   67   68   69   70   71   72   73   ...   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