paquechu,
Nota: La función GetFileLastLine del código del Msg #36 se modifico para adaptarse a
posibles operaciones de Delete en el archivo monitoreado por medio de la Actualización del Valor de Control (Tamaño del archivo monitoreado), como se muestra a continuación:
Código Delphi
[-]
function TDirectoryMonitor.GetFileLastLine(const FileName: string): string;
var
F1 : TFileStream;
F2 : TFileStream;
Buffer : string;
BufChar : Char;
i, pi, pf : Integer;
LastSize : LongWord;
Err : Integer;
FileControl : String;
begin
try
FileControl := ExtractFilePath(Application.ExeName) + 'FileControl.txt';
F1 := TFileStream.Create(FileControl, fmOpenReadWrite or fmShareDenyNone);
SetLength(Buffer, F1.Size);
F1.Read(Buffer[1],F1.size);
Val(Buffer, LastSize,Err);
F2 := TFileStream.Create(FileName, fmOpenRead or fmShareDenyNone);
pi := -1;
pf := LastSize - F2.Size;
Result := '';
if (LastSize = 0) then
begin
pf := 0;
F2.Seek(0,soFromBeginning);
while F2.Position < F2.Size do
begin
F2.Read(BufChar, 1);
Result := Result + BufChar;
end;
Buffer := Format('%.10d',[F2.Size]);
F1.Seek(0,soFromBeginning);
F1.Write(Buffer[1],Length(Buffer));
end;
if (pf < 0) then
begin
pf := pf - 1;
repeat
F2.Seek(pi, soFromEnd);
F2.Read(BufChar, SizeOf(BufChar));
Insert(BufChar, Result, 1);
Dec(pi);
until (pi = pf);
Buffer := Format('%.10d',[F2.Size]);
F1.Seek(0,soFromBeginning);
F1.Write(Buffer[1],Length(Buffer));
end;
if (pf > 0) then
begin
Buffer := Format('%.10d',[F2.Size]);
F1.Seek(0,soFromBeginning);
F1.Write(Buffer[1],Length(Buffer));
end;
finally
F1.Free;
F2.Free;
end;
end;
Esta modificación solo ajusta el valor de control en el caso de que el archivo monitoreado disminuya su tamaño,
no se registra el cambio en el control TListBox.
El nuevo código modificado esta disponible en el link:
http://terawiki.clubdelphi.com/Delph...i%F3n+2%29.rar
Espero sea útil
Nelson.