1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45:
| procedure TParseThread.execute; var AHStream : THandleStream; AFileHandle : THandle; str, nstr: string; buf: TBytes; enc: TEncoding; LOffset: Integer; s: int64; begin if not FileExists(pfile) then Exit;
AFileHandle := CreateFile(PChar(pfile), GENERIC_READ, FILE_SHARE_READ or FILE_SHARE_WRITE, nil, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
if AFileHandle <> INVALID_HANDLE_VALUE then begin AHStream := THandleStream.Create(AFileHandle);
s := ahstream.Size; enc:= nil; setlength(buf, s); ahstream.ReadBuffer(Pointer(buf)^, s); LOffset := TEncoding.GetBufferEncoding(buf, enc); str := enc.GetString(buf, loffset, s-loffset);
str := ''; repeat while ahstream.Position = ahstream.Size do application.ProcessMessages; sleep(10);
setlength(buf, 1); ahstream.ReadBuffer(pointer(buf)^, 1); nstr := enc.GetString(buf, 0, 1); if nstr <> #10 then str := str + nstr; if nstr = #13 then begin
parse(str);
str := ''; end; until false;
FreeAndNil(AHStream); CloseHandle(AFileHandle); end; end; |