pascalabcnet/TestSuite/CompilationSamples/__RunMode.pas
Бондарев Иван 59169b5168 ...
2015-06-27 18:33:50 +02:00

64 lines
1.8 KiB
ObjectPascal

// Copyright (c) Ivan Bondarev, Stanislav Mihalkovich (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
///--
unit __RunMode;
//------------------------------------------------------------------------------
// Ìîäóëü, ïîäêëþ÷àåìûé â ðåæèìå çàïóñêà áåç ñâÿçè ñ îáîëî÷êîé
// (ñ) DarkStar 2007
// Ôóíêöèè:
// 1. Ïåðåõâàò èñêëþ÷åíèé ïî AppDomain.CurrentDomain.UnhandledException è
// âûâîä èõ â êîíñîëü
// 2. Åñëè ýòî - êîíñîëüíîå îêíî, òî óñòàíàâëèâàåò èìÿ çàãîëîâêà íà èìÿ exe-ôàéëà
//------------------------------------------------------------------------------
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.