Or Keyword
The or
operator performs a logical
or if the operands are of Boolean type or a
bitwise or if the operators are integers.
Integer operands can be of any integer type, including
Int64
. A logical or is False
only if both operands are False and is True if either operand is
True.
Unlike standard Pascal, if the left-hand operand is True, Delphi does
not evaluate the right-hand operand because the result must be True.
You can avoid this shortcut operation and return to standard Pascal
with the $BoolEval
or $B
compiler directives.
An integer or
operates on each bit of its
operands, setting the result bit to 1 if either operand has a 1 bit,
and sets a bit to
if both operands have
bits. If one operand is smaller than the other, Delphi extends the
smaller operand with
in the leftmost bits. The result is the size of the largest operand.
var I, J: Integer; S: string; begin I := $25; J := $11; WriteLn(I or J); // Writes 53 (which is $35) ... // The short-circuit behavior of OR in the next example prevents // Delphi from referring to the nonexistent string element at // the end of the string, in case the string is empty. if (Length(S) = 0) or (S[Length(S)] <> '') then S := S + '';