Name
Or Keyword
Syntax
Boolean expression
orBoolean expression
Integer expression
orInteger expression
Description
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.
Tips and Tricks
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.
Examples
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 + '\';
See Also
And Keyword, Boolean Type, ByteBool Type, LongBool Type, Not Keyword, Shl Keyword, Shr Keyword, WordBool Type, Xor Keyword, $B Compiler Directive, $BoolEval Compiler Directive ... |
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.