delphi - avoid complete check of an if statement -
the code sample below should evaluate string.
function evaluatestring(const s: ansistring): ansistring; var i, l: integer; begin l := length(s); i:=1; if (l > 0) , (s[i] > ' ') , (s[l] > ' ') ..... end;
but if l=0 (s[i] > ' ')
create access violation. can avoid problem while keeping if
condition?
you need either put {$b-}
statement on top of code, or enable boolean short circuit evaluation in project settings.
since {$b-}
default, may have turned on before, or there {$b+}
directive somewhere turning off.
in short circuit evaluation mode {$b-}
, delphi creates code (roughly) equivalent this:
if (l > 0) begin if (s[i] > ' ') begin if (s[l] > ' ') begin ..... end; end; end;
in contrast, full boolean evaluation mode {$b+}
, equivalent this:
var a,b,c : boolean; := (l > 0); b := (s[i] > ' '); // executed c := (s[l] > ' '); // executed if , b , c .....
Comments
Post a Comment