Name
Or Keyword
Syntax
Boolean expressionorBoolean expressionInteger expressionorInteger 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
$BoolEvalor$Bcompiler directives.An integer
oroperates 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 ... |
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access