Relational operators

Navigation:  Les scripts > Les autres scripts >

Relational operators

Previous pageReturn to chapter overviewNext page

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,        Boolean                I = Max

                         string, packed string

<>                inequality        simple, class, class reference, interface,        Boolean                X <> Y

                               string, packed strin

<                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 <= I

>=                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.

 

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

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

3) 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.

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

5) 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.