Ver Mensaje Individual
  #17  
Antiguo 25-03-2013
Avatar de ecfisa
ecfisa ecfisa is offline
Moderador
 
Registrado: dic 2005
Ubicación: Tres Arroyos, Argentina
Posts: 10.508
Reputación: 36
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 paquechu.

Dado que la aplicación que genera el log añade líneas, este cambiará su tamaño. Entonces, una forma de detectar si se agregó una linea usando un TTimer, podría ser:
Código Delphi [-]
  ...
  private
    FPreviousSize: Int64; // Ultimo tamaño monitoreado   
  end;

...

implementation

const
   NOMARCH = 'C:\LOG.TXT'; // Ruta hasta y nombre del archivo

(* Obtener tamaño del archivo *)
function FileLongSize(const aFileName: string): Int64;
var
  FindData: TWin32FindData;
begin
  Windows.FindClose(FindFirstFile(PChar(aFileName), FindData));
  Result := FindData.nFileSizeHigh shl 32 + FindData.nFileSizeLow;
end;

(* Obtener última línea *)
function GetLastLine(const aFileName: string): string;
var
  FS  : TFileStream;
  buf : Char;
  i   : Integer;
begin
  FS := TFileStream.Create(aFileName, fmOpenRead);
  try
    Result := '';
    i := FS.Size + 2;
    repeat
      FS.Seek(FS.Size-i, soEnd);
      FS.Read(buf, SizeOf(buf));
      Insert(buf, Result, 1);
      Inc(i);
    until (buf = #10);
  finally
    FS.Free;
  end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  // Tamaño al inicio del monitoreo
  FPreviousSize:= FileLongSize(NOMARCH); 
  //Timer1.Interval := ??? (a tu necesidad)
end;

procedure TForm1.Timer1Timer(Sender: TObject);
var
  NewSize: Int64;
begin
  NewSize:= FileLongSize(NOMARCH);  // Nuevo tamaño
  if FPreviousSize <>  NewSize then 
  begin
    FPreviousSize:= NewSize;
    Timer1.Enabled:= False;
    // Aca lo que gustes hacer con la última línea, para el ejemplo la muestro.
    MessageBox(Handle,PChar(GetLastLine(NOMARCH)),'NUEVA LINEA',MB_ICONEXCLAMATION);
    Timer1.Enabled:= True;
  end;
end;
...
No sé si es la forma mas optima, pero es simple y en mis pruebas funciona. Hasta que encuentres algo mejor tal vez te sirva...

Saludos.
__________________
Daniel Didriksen

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