/
YakuninAV
/
Convertors
Обзор
Документация
Войти
/
YakuninAV
/
Convertors
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
Core/DBDNotifiers.pas
164 строки
5 KB
YakuninAV
begin with gitflick
31 июл 2026, 15:21
31 июл 2026, 15:21
1dc0fc6
Код
Авторство
О чём код?
unit DBDNotifiers; {$I mormot.defines.inc} interface uses {$I mormot.uses.inc} SysUtils, Classes, {$IFNDEF CONSOLE} {$IFDEF ISDELPHIXE2} vcl.StdCtrls, {$ELSE} StdCtrls, {$ENDIF} {$ENDIF} mormot.core.base, mormot.core.os, mormot.core.unicode, mormot.lib.static, mormot.core.zip, mormot.core.data, {$IFDEF CONSOLE} mormot.app.console, {$ENDIF} DBDIntfs; type {$IFNDEF CONSOLE} /// Нотификатор для вывода сообщений в TMemo TDBDNotifierMemo = class(TDBDNotifier) private Owner: TComponent; mLog: TMemo; public constructor Create(Control: TComponent); destructor Destroy; override; /// Функция выводит сообщения в Memo. Функция возвращает True, если пользователь, после обработки сообщения, // ппринял решение прекратить выполнение процедуры, которая выдала сообщение // MsgKind - тип сообщения // MsgCode - код связанный с сообщением // MsgText - текст сообщения function Log(const MsgKind: TDBDMessageKind; const MsgCode: Integer; const MsgText: string): Boolean; override; end; {$ELSE} TDBDNotifierConsole = class(TDBDNotifier) private cmd: ICommandLine; public constructor Create; /// Функция выводит сообщения на консоль. Функция возвращает True, если пользователь, после обработки сообщения, // ппринял решение прекратить выполнение процедуры, которая выдала сообщение // MsgKind - тип сообщения // MsgCode - код связанный с сообщением // MsgText - текст сообщения function Log(const MsgKind: TDBDMessageKind; const MsgCode: Integer; const MsgText: string): Boolean; override; end; {$ENDIF} TDBDNotifierFile = class(TDBDNotifier) private FLogFile: TFileName; ls: TStringList; public constructor Create(const FName: TFileName); destructor Destroy; override; /// Функция выводит сообщения текстовый файл. Функция возвращает True, если пользователь, после обработки сообщения, // ппринял решение прекратить выполнение процедуры, которая выдала сообщение // MsgKind - тип сообщения // MsgCode - код связанный с сообщением // MsgText - текст сообщения function Log(const MsgKind: TDBDMessageKind; const MsgCode: Integer; const MsgText: string): Boolean; override; end; var DBDNotifier: IDBDNotifierV1; procedure Notify(Notifier: IDBDNotifierV1; const msgKind: TDBDMessageKind; const msgText: string); inline; implementation procedure InitModule; begin DBDNotifier:= TDBDNotifier.Create(nil); end; procedure Notify(Notifier: IDBDNotifierV1; const msgKind: TDBDMessageKind; const msgText: string); inline; begin if Notifier<>nil then Notifier.Log(msgKind, 0, msgText); end; {$IFNDEF CONSOLE} { TDBDNotifierMemo } constructor TDBDNotifierMemo.Create(Control: TComponent); begin inherited Create(nil); Owner:= Control; if Control is TCustomMemo then mLog:=TMemo(Control) else mLog:=nil; end; destructor TDBDNotifierMemo.Destroy; begin inherited; end; function TDBDNotifierMemo.Log(const MsgKind: TDBDMessageKind; const MsgCode: Integer; const MsgText: string): Boolean; var s: string; begin if Assigned(mLog) then begin s:=MsgKindStr(MsgKind); if (MsgKind=dmkIteration) and (MsgCode>=0) and (s = copy(mLog.Lines[mLog.Lines.Count-1],1,Length(s))) then mLog.Lines[mLog.Lines.Count-1]:=(s + Format('|%6.6d|',[MsgCode]) + MsgText) else mLog.Lines.Add(s + Format('|%6.6d|',[MsgCode]) + MsgText); end; Result := False; end; {$ELSE} { TDBDNotifierConsole } constructor TDBDNotifierConsole.Create; begin inherited Create(nil); cmd:=TCommandLine.Create; end; function TDBDNotifierConsole.Log(const MsgKind: TDBDMessageKind; const MsgCode: Integer; const MsgText: string): Boolean; var r: RawUTF8; begin Result:=False; {$IFDEF FPC} cmd.Text('%',[FormatMsg(MsgKind,MsgCode,MsgText)]); {$ELSE} r:=StringToUTF8(FormatMsg(MsgKind,MsgCode,MsgText)); cmd.Text('%',[r]); {$ENDIF} end; {$ENDIF} { TDBDNotifierFile } constructor TDBDNotifierFile.Create(const FName: TFileName); begin inherited Create(nil); ls:=TStringList.Create; FLogFile:=FName; end; destructor TDBDNotifierFile.Destroy; begin try if FLogFile<>'' then ls.SaveToFile(FLogFile); except on E: Exception do ShowException(E, ExceptAddr); end; ls.Free; inherited; end; function TDBDNotifierFile.Log(const MsgKind: TDBDMessageKind; const MsgCode: Integer; const MsgText: string): Boolean; begin Result:=ls.Add(TDBDNotifier.FormatMsg(MsgKind, MsgCode, MsgText))<0; end; initialization InitModule; end.