title: How to set ExitCode in a VCL Forms Application
body: <p>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 <code>ExitCode := 42;</code> at the end.</p>
  
  <pre><code>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.
  </code></pre>
  
  <p>Now, when I run it from the command line, <code>%ERRORLEVEL%</code> doesn't get set:</p>
  
  <pre><code>&gt;.\Test.exe
  
  &gt;echo %ERRORLEVEL%
  0
  </code></pre>
  
  <p>I was expected the value in <code>%ERRORLEVEL%</code> to be 42, but it isn't being updated.</p>
  
  <p>I tried the same experiment in a console application, and that worked fine. Why isn't it working for my GUI application?</p>