Club Delphi  
    Paypal   FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Principal > Varios
Registrarse FAQ Miembros Calendario Guía de estilo Temas de Hoy

Coloboración Paypal con ClubDelphi

 
 
Herramientas Buscar en Tema Desplegado
  #17  
Antiguo 25-03-2013
Avatar de ecfisa
ecfisa ecfisa is offline
Moderador
 
Registrado: dic 2005
Ubicación: Tres Arroyos, Argentina
Posts: 10.508
Poder: 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 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
 



Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro


La franja horaria es GMT +2. Ahora son las 10:35:59.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi
Copyright 1996-2007 Club Delphi