Chapter 7. Operators
This chapter describes the symbolic operators, their precedence and semantics. Chapter 5, describes the named operators in depth, but not the symbolic operators, because it’s hard to alphabetize symbols. This chapter describes the symbolic operators in depth.
Delphi defines the following operators. Each line lists the operators with the same precedence; operator precedence is highest at the start of the list and lowest at the bottom:
@ not ^ + - (unary operators) |
* / div mod and shl shr as
|
+ - or xor
|
> < >= <= <> = in is
|
A Variant
can be a string, number, Boolean, or
other value. If an expression mixes Variant
and
non-Variant
operands, Delphi converts all operands
to Variant
. If the Variant
types do not match, Delphi casts one or both operands as needed for
the operation, and produces a Variant
result. See
the Variant
type in Chapter 5
for more information about Variant
type
casts.
Unary Operators
-
@
operator Returns the address of its operand. The address of a variable or ordinary subroutine is a
Pointer
, or if the$T
or$TypedAddress
compiler directive is used, a typed pointer (e.g.,PInteger
).The address of a method has two parts: a code pointer and a data pointer, so you can assign a method address only to a variable of the appropriate type, and not to a generic
Pointer
variable. If you take the address of a method using a class reference instead of an object reference, the@
operator returns just the code pointer. For example:
Ptr := @TObject.Free;
Get Delphi in a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.