Описание:
Директива компилятора $B указывает Delphi, нужно
ли продолжать вычисление многоаргументного булевого выражения, когда результат
известен еще до завершения вычисления.
{$B-}
(по умолчанию) означает не продолжать, {$B+} означает продолжать проверку.
Например, по умолчанию, с выражением:
expr1 and expr2
expr2 не вычисляется, если expr1 ложно. С
{$B+}, проверка будет продолжена.
Пример
иллюстрирует использование установки по умолчанию.
Пример кода:
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;
Результат выполнения:
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