testappexit.pp 554 B

123456789101112131415161718192021222324252627282930313233
  1. program testappexit;
  2. {$mode objfpc}
  3. {$h+}
  4. uses sysutils,custapp;
  5. type
  6. TApplication = Class(TCustomApplication)
  7. Procedure DoRun; override;
  8. end;
  9. Procedure TApplication.DoRun;
  10. begin
  11. ExceptionExitCode:=9;
  12. If ParamStr(1)='-h' then
  13. Terminate(10)
  14. else if Paramstr(1)='-e' then
  15. Raise Exception.Create('Stopping with exception')
  16. else
  17. Writeln('Normal stop');
  18. Terminate;
  19. end;
  20. begin
  21. With TApplication.Create(Nil) do
  22. try
  23. StopOnException:=True;
  24. Initialize;
  25. Run;
  26. finally
  27. Free;
  28. end;
  29. end.