Operators
behave like predefined functions that are part of the Object Pascal language.
For example, the expression (X + Y) is built from the variables X and Y called operands
with the + operator; when X and Y represent integers or reals, (X + Y) returns
their sum. Operators include @, not, ^, *, /,
div, mod, and, shl, shr, as, +,
-, or, xor, =, >, <, <>,
<=, >=, in, and is.
The
operators @, not, and ^ are unary (taking one
operand). All other operators are binary (taking two operands), except
that + and - can function as either unary or binary. A unary operator always precedes
its operand (for example, -B), except for ^, which follows its operand
(for example, P^). A binary operator is placed between its operands (for
example, A = 7).
Some
operators behave differently depending on the type of data passed to them. For
example, not performs bitwise negation on an integer operand and logical
negation on a Boolean operand. Such operators appear below under multiple
categories.
Except
for ^, is, and in, all operators can take operands of type
Variant.
The
sections that follow assume some familiarity with Object Pascal data types.
For
information about operator precedence in complex expressions, see Operator precedence rules.
运算符作为Object Pascal语言的组成部分,其表现与预定义函数相似。例如,表达式 (X + Y) 由变量X和变量Y以及 + (加号)运算符构成;当X和Y代表整数或实数时,(X + Y)返回它们的和;这里的X和Y叫做操作数。运算符包括@, not, ^, *,
/, div, mod, and, shl, shr, as, +, -, or, xor, =, >, <, <>, <=,
>=, in, is等。
运算符@、not和
^ 是一元运算符(只接受一个操作数)。除了加号(+)和减号(-)既可以作为一元运算符又可以作为二元运算符之外,所有其他的运算符都是二元运算符(接受两个操作数)。一元运算符中,除了
^ 位于其操作数后(如P^)外,其他的总位于操作数前(如 -B)。二元运算符总是位于两个操作数之间(如 A=7)。
有些运算符对不同类型的数据其运算也不同。例如,not运算符对整数操作数进行逐位否定,而对布尔操作数进行逻辑否定。因此,这样的运算符将在下面出现在多个分类中。
除了 ^、is、in,所有的运算符都能接受变体(Variant)类型的操作数。
下面有关运算符的章节假定读者对Object Pascal数据类型有所熟悉。
关于混合表达式中运算符的优先级,见运算符优先规则。