Beware of Exit
command usage in inline functions! I have been using Delphi XE3 here.
Symptom
In certain circumstances, when a call is made to an inline function that contains Exit
command, and the return value of the inline function is used directly in WriteLn()
, the compiler reports an error message,
"dcc" exited with code 1.
or even worst, the Delphi IDE terminates without any confirmation.
function ProcessNumber(const iNumber: Integer): Boolean; inline;
begin
if iNumber = 0 then begin
Result := False;
Exit;
end;
// some code here ...
Result := True;
end;
procedure Test;
begin
writeln( ProcessNumber(0) );
end;
begin
Test;
ReadLn;
end.
However, if the return value of the inline function is stored in a variable, and then the variable is used in WriteLn()
, the problem does not occur.
procedure Test;
var
b: Boolean;
begin
b := ProcessNumber(0);
writeln(b);
end;
Questions
- Is this a compiler bug?
- If this a bug, is there a workaround to safely exit from an inline function?
inline
doesn't change whatexit
means. It's the internal AV that kills the IDE that is the problem. – Haddington