2020-02-23 02:00:43 +03:00
|
|
|
|
// Copyright (c) Ivan Bondarev, Stanislav Mikhalkovich (for details please see \doc\copyright.txt)
|
2015-06-27 19:33:50 +03:00
|
|
|
|
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
2015-05-14 22:35:07 +03:00
|
|
|
|
///--
|
|
|
|
|
|
unit __RunMode;
|
|
|
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
2015-12-28 14:25:15 +03:00
|
|
|
|
// Модуль, подключаемый в режиме запуска без связи с оболочкой
|
|
|
|
|
|
// (с) 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);
|
2020-02-23 02:00:43 +03:00
|
|
|
|
|
|
|
|
|
|
var _a := new string[_CommandLineArgs.Length-1];
|
|
|
|
|
|
for var i:=1 to _CommandLineArgs.Length-1 do
|
|
|
|
|
|
_a[i-1] := _CommandLineArgs[i];
|
|
|
|
|
|
_CommandLineArgs := _a;
|
|
|
|
|
|
|
2015-05-14 22:35:07 +03:00
|
|
|
|
end;
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure __InitModule__;
|
|
|
|
|
|
begin
|
|
|
|
|
|
if not __initialized then
|
|
|
|
|
|
begin
|
|
|
|
|
|
__initialized := true;
|
2015-08-12 19:11:45 +03:00
|
|
|
|
__InitPABCSystem;
|
2015-05-14 22:35:07 +03:00
|
|
|
|
__InitModule;
|
|
|
|
|
|
end;
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
begin
|
|
|
|
|
|
__InitModule;
|
|
|
|
|
|
end.
|