Originale-mail to me for new edition

 

Relational operators

 

Relational operators are used to compare two operands. The operators =, <>, <=, and >= also apply to sets (see Set operators); = and <> also apply to pointers (see Pointer operators).

 

Operator

Operation

Operand types

Result type

Example

=

equality

simple, class, class reference, interface, string, packed string

Boolean

I = Max

<>

inequality

simple, class, class reference, interface, string, packed string

Boolean

X <> Y

<

less-than

simple, string, packed string, PChar

Boolean

X < Y

>

greater-than

simple, string, packed string, PChar

Boolean

Len > 0

<=

less-than-or-equal-to

simple, string, packed string, PChar

Boolean

Cnt <= 1

>=

greater-than-or-equal-to

simple, string, packed string, PChar

Boolean

I >= 1

 

For most simple types, comparison is straightforward. For example, I = J is True just in case I and J have the same value, and I <> J is True otherwise. The following rules apply to relational operators.

·  Operands must be of compatible types, except that a real and an integer can be compared.

·  Strings are compared according to the ordering of the extended ASCII character set. Character types are treated as strings of length 1.

·  Two packed strings must have the same number of components to be compared. When a packed string with n components is compared to a string, the packed string is treated as a string of length n.

·  The operators <, >, <=, and >= apply to PChar operands only if the two pointers point within the same character array.

·  The operators = and <> can take operands of class and class-reference types. With operands of a class type, = and <> are evaluated according the rules that apply to pointers: C = D is True just in case C and D point to the same instance object, and C <> D is True otherwise. With operands of a class-reference type, C = D is True just in case C and D denote the same class, and C <> D is True otherwise. For more information about classes, see Classes and objects.

 

Topic groups

 

See also

About operators

Operator precedence rules

 

 

译文

 

关系运算符

 

关于运算符运用比较两个操作数。关系运算符 =<><=>= 也适用于集合(见集合运算符);= <> 也适用于指针(见指针运算符)。

 

运算符

操作

操作数类型

结果类型

范例

=

相等

简单类型、类、类引用、接口、串、压缩串

Boolean

I = Max

<>

不等

简单类型、类、类引用、接口、串、压缩串

Boolean

X <> Y

<

小于

简单类型、串、压缩串、PChar

Boolean

X < Y

>

大于

简单类型、串、压缩串、PChar

Boolean

Len > 0

<=

小于或等于

简单类型、串、压缩串、PChar

Boolean

Cnt <= 1

>=

大于或等于

简单类型、串、压缩串、PChar

Boolean

I >= 1

 

对于大多数简单类型,比较是直接进行的。例如,当IJ具有相同的值是,I = JTrue,否则I <> JTrue。下列规则适用于关系运算符:

·  除实数和整数可以比较之外,用于比较的操作数必需类型兼容

·  串的比较依照扩展ASCII字符集的顺序;字符类型被视为长度为1的串。

·  用于比较的两个压缩串,它们的分量(构成压缩串的最小单位)必需在数量上相同。当含有n个分量的压缩串与串作比较时,压缩串被视为长度为n的串。

·  运算符 <><=>= 适用于PChar类型的操作数,仅当两个指针指向相同的字符数组时。

·  运算符 = <> 可以将类类型和类引用类型作为操作数。对于类类型的操作数,运算符 = <> 的判定依照适用于指针的规则:当CD指向相同的实例对象时,C = DTrue,否则C <> DTrue;对于类引用类型的操作数,仅当CD表示相同的类时,C = DTrue,否则C <> DTrue 更多关于类的信息,见类和对象

 

主题组

 

相关主题

运算符

运算符优先规则