Logical operators perform conditional and, or, and not operations. Some languages support both binary logical operators that link two and unary logical operators negate (make opposite) the truth value of its argument. Finally, some languages short circuit logic. For example, with this or that, if this is an expression returning true, then that is never executed.
Delphi Logical Operators
Delphi logical operators:
and
and, as in this and that
or
or, as in this or that
not
Not, as in Not This
xor
either or, as in this or that but not both
The Delphi compiler default is to short circuit multi argument boolean expressions when the result is known before the evaluation completes. To disable short circuiting, use the {$B+} compiler directive. To reset it back to the compiler default of short circuting, use the {$B-} compiler directive.
Syntax Example:
//Given expressions a, b, c, and d:
if Not (a and b) and (c or d) then
//Do something.
Using the Logical Not Operator
You can use the not operator in many contexts. One of my favorite uses for it is to toggle boolean properities with a single line of code:
BooleanProperty = Not BooleanProperty;
For example, if you have an Image control on a form you can toggle it's visibility with a single line of code:
The following are practice certification questions with answers highlighted. These questions were prepared by Mike Prestwood and are intended to stress an important aspect of this KB post. All our practice questions are intended to prepare you generally for passing any certification test as well as prepare you for professional work.