pascalabcnet/TestSuite/formatter_tests/input/__RunMode.pas

62 lines
1.8 KiB
ObjectPascal
Raw Permalink Normal View History

2015-05-14 22:35:07 +03:00
///--
unit __RunMode;
//------------------------------------------------------------------------------
// Модуль, подключаемый в режиме запуска без связи с оболочкой
// (с) DarkStar 2007
// Функции:
// 1. Перехват исключений по AppDomain.CurrentDomain.UnhandledException и
// вывод их в консоль
// 2. Если это - консольное окно, то устанавливает имя заголовка на имя exe-файла
2015-05-14 22:35:07 +03:00
//------------------------------------------------------------------------------
interface
///--
procedure __InitModule__;
implementation
uses PABCSystem, System;
procedure DbgExceptionHandler(sender: object; args: UnhandledExceptionEventArgs);
begin
var e := Exception(args.ExceptionObject);
if args.IsTerminating and (ExecuteBeforeProcessTerminateIn__Mode<>nil) then
ExecuteBeforeProcessTerminateIn__Mode(e);
if IsConsoleApplication then begin
Console.Error.Write('Unhandled Exception: ' + e.ToString);
if args.IsTerminating then
Halt;
end else
raise e;
end;
var __initialized := false;
procedure __InitModule;
begin
if (CommandLineArgs.Length>0) and (CommandLineArgs[0]='[RUNMODE]') and not ExecuteAssemlyIsDll then begin
AppDomain.CurrentDomain.UnhandledException += DbgExceptionHandler;
if IsConsoleApplication then
Console.Title := ExtractFileName(GetEXEFileName);
var _a := new string[CommandLineArgs.Length-1];
for var i:=1 to CommandLineArgs.Length-1 do
_a[i-1] := CommandLineArgs[i];
CommandLineArgs := _a;
end;
end;
procedure __InitModule__;
begin
if not __initialized then
begin
__initialized := true;
PABCSystem.__InitModule__;
__InitModule;
end;
end;
begin
__InitModule;
end.