1 {$B-}
2 {$B+}
Description
The $B compiler directive tells Delphi whether to continue a multi argument boolean expression evaluation when the result is known before evaluation completes.
{$B-} (default) means no continue {$B+} means continue checking
For example, by default, with an expression :
expr1 and expr2
expr2 is not evaluated if expr1 is false. With {$B+}, checking would have continued.
The example illustrates a normal use of the default.
Notes
$B is equivalent to $BoolEval.
This directive can be used multiple times within your code.
The default value is $B-
Related commands
$BoolEval Whether to short cut and and or operations
And Boolean and or bitwise and of two arguments
If Starts a conditional expression to determine what to do next
Or Boolean or or bitwise or of two arguments
Example code : Checking string contents
var
FullString, EmptyString : string;
begin
FullString := 'Fred';
EmptyString := '';
// Set full checking OFF
{$B-}
// Check the 4th character of each string
if (Length(FullString) >= 4) and (FullString[4] = 'd')
then ShowMessage('FullString 4th character is d')
else ShowMessage('FullString 4th character is NOT d');
if (Length(EmptyString) >= 4) and (EmptyString[4] = 'd')
then ShowMessage('EmptyString 4th character is d')
else ShowMessage('EmptyString 4th character is NOT d');
// Set full checking ON
{$B+}
// Check the 4th character of each string
if (Length(FullString) >= 4) and (FullString[4] = 'd')
then ShowMessage('FullString 4th character is d')
else ShowMessage('FullString 4th character is NOT d');
// Now we must protect the code from errors
try
if (Length(EmptyString) >= 4) and (EmptyString[4] = 'd')
then ShowMessage('EmptyString 4th character is d')
else ShowMessage('EmptyString 4th character is NOT d');
except
on E : EAccessViolation do
ShowMessage(E.Message);
end;
end;
Show full unit code
The following is typical of the output from the above code:
FullString 4th character is d
EmptyString 4th character is NOT d
FullString 4th character is d
Access violation at address 00442196 in module 'PROJECT1.EXE'.
Read of address FFFFFFFF