Описание:
Директива компилятора $BoolEval указывает Delphi,
нужно ли продолжать вычисление многоаргументного булевого выражения, когда
результат известен еще до завершения вычисления.
{$BoolEval Off} (по умолчанию) означает не
продолжать, {$BoolEval On} означает продолжать проверку.
Например, по умолчанию, с выражением:
expr1 and expr2
expr2 не вычисляется, если expr1 ложно. С
{$BoolEval On}, проверка будет продолжена.
Пример иллюстрирует использование установки по умолчанию.
Пример кода:
var
FullString, EmptyString :
string;
begin
FullString := 'Fred';
EmptyString := '';
// Set full checking OFF
{$BoolEval Off}
// 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
{$BoolEval On}
// 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