I can't get ExitCode to work for a VCL forms application. Here is my test application. It was created from the File / New menu in the Delphi 2007 IDE. The only change is that I added the line ExitCode := 42;
at the end.
program Test;
uses
Forms,
Unit27 in 'Unit27.pas' {Form27};
{$R *.res}
begin
Application.Initialize;
Application.MainFormOnTaskbar := True;
Application.CreateForm(TForm27, Form27);
Application.Run;
ExitCode := 42;
end.
Now, when I run it from the command line, %ERRORLEVEL%
doesn't get set:
>.\Test.exe
>echo %ERRORLEVEL%
0
I was expected the value in %ERRORLEVEL%
to be 42, but it isn't being updated.
I tried the same experiment in a console application, and that worked fine. Why isn't it working for my GUI application?
You can establish the exit code like you're doing, but on the console you have to test the %errorlevel% variable in the same batch to get the value.
Instead of running your commands in the command prompt, create a simple bat like this:
REM calltest.bat
.\Test.exe
echo %ERRORLEVEL%
and then, invoke your test:
>calltest
I got this in my test:
>calltest.bat
>project3.exe
>echo 47
For both, setting directly the ExitCode
variable or calling Halt
.
My OS is Win7 64, if it makes any difference. Printing the %errorlevel%
directly from the command line prints 0.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With