Ver Mensaje Individual
  #3  
Antiguo 03-06-2013
Avatar de ecfisa
ecfisa ecfisa is offline
Moderador
 
Registrado: dic 2005
Ubicación: Tres Arroyos, Argentina
Posts: 10.508
Reputación: 38
ecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to behold
Hola cristianvera17.

Te pongo una posible implementación, espero te sirva de guía:
Código Delphi [-]
unit uLog;

interface

uses SysUtils,Classes,Forms;

type
  TLog = class(TObject)
  private
    FPath    : string;
    FFileName: string;
    FStream  : TFileStream;
    function DateExists(const aFileName: string): boolean;
  public
    constructor Create; reintroduce; overload;
    procedure SaveLog(const LogStr: string);
    destructor Destroy; override;
  end;

implementation

function TLog.DateExists(const aFileName: string): boolean;
var
  SR: TSearchRec;
begin
  Result := FindFirst(FPath+Copy(aFileName,1,10)+'*.txt', faArchive, SR) = 0;
end;

constructor TLog.Create;
begin
  FPath     := ExtractFilePath(Application.ExeName);
  FFileName := FormatDateTime('dd-mm-yyyy_hh-mm-ss',Now)+'_log.txt';
  if not DateExists(FFileName) then
    FStream := TFileStream.Create(FPath+FFileName, fmCreate)
  else
    raise Exception.Create('Ya existe un archivo Log con esta fecha');
end;

procedure TLog.SaveLog(const LogStr: string);
begin
  with FStream do
  begin
    Seek(0, soFrombeginning);
    Write(LogStr[1],Length(LogStr));
  end;
end;

destructor TLog.Destroy;
begin
   if Assigned(FStream) then
    FStream.Free;
  inherited Destroy;
end;
end.

Ejemplo de llamada:
Código Delphi [-]
implementation

uses uLog;

...
begin
  with TLog.Create do
  try
    SaveLog('Hasta ahora no ha sucedido nada...');
  finally
    Free;
  end;
end;

Saludos
__________________
Daniel Didriksen

Guía de estilo - Uso de las etiquetas - La otra guía de estilo ....
Responder Con Cita