Solo me quedaba mencionar que DMMain.Log(), DMMain.LogIni() y DMMain.LogFin() son procedimiento que guardan strings en un archivo.
Solo lo hacen si está establecida la directiva de compilación Debug
Código Delphi
[-]
TDMMain = class(TDataModule)
[...]
private
ContadorLog: integer;
InicioLog: array[1..20] of TDateTime;
[...]
procedure TDMMain.Log(s: string);
{$IFDEF Debug}
var
F : TextFile;
FileName : string;
{$ENDIF}
begin
{$IFDEF Debug}
FileName := ChangeFileExt(Application.ExeName, '.log');
AssignFile(F, FileName);
try
Append(F);
except
try
Rewrite(F);
except
on e: Exception do
ShowMessage('Error al abrir fichero : ' + FileName + #13#10 + e.Message);
end;
end;
WriteLn(F, FormatDatetime('[yyyy-mm-dd hh:nn:ss.zzz] ', Now) + s);
CloseFile(F);
{$ENDIF}
end;
procedure TDMMain.LogIni(s: string);
var
espacio : string;
i : integer;
begin
Inc(ContadorLog);
espacio := '';
for i := 2 to ContadorLog do
espacio := espacio + ' ';
if (ContadorLog < 20) then
InicioLog[ContadorLog] := Now;
Log('I - ' + espacio + s);
end;
procedure TDMMain.LogFin(s: string);
var
espacio : string;
i : integer;
begin
espacio := '';
for i := 2 to ContadorLog do
espacio := espacio + ' ';
if (ContadorLog < 20) then
Log('F - ' + espacio + FormatDatetime('[nn:ss.zzz]', Now - InicioLog[ContadorLog]) + ' - ' + s)
else
Log('F - ' + espacio + FormatDatetime('[nn:ss.zzz]', Now - Now) + ' - ' + s);
if (ContadorLog > 0) then
Dec(ContadorLog);
end;