Advertisement
Guest User

FileSize

a guest
Mar 26th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 1.13 KB | None | 0 0
  1. function GetDataFromFile;
  2.   var
  3.     CurrentFile : TFileByte; // file of Byte
  4.     NumOfCharLeft : Integer;
  5.   begin
  6.     Assign(CurrentFile, PathToFile);
  7.     Reset(CurrentFile);                
  8.     NumOfCharLeft := FileSize(CurrentFile) - NumOfCharRead;
  9.     Seek(CurrentFile, NumOfCharRead);
  10.  
  11.     { Читаем информацию из файла (CurrentFile) и помещаем
  12.       данные в буфер (Buffer). Когда размер не прочитанной
  13.       информации с файла меньше размера буфера,
  14.       то считываем оставшуюся информацию и устанавливаем
  15.       значение "True" в IsEndOfFile }
  16.  
  17.     if (NumOfCharLeft < BufferSize) then
  18.     begin
  19.       SetLength(Result, NumOfCharLeft);
  20.       BlockRead(CurrentFile, PChar(Result)^, NumOfCharLeft);
  21.       IsEndOfFile := True;
  22.     end
  23.     else if (NumOfCharLeft > BufferSize) then
  24.     begin
  25.       SetLength(Result, BufferSize);
  26.       BlockRead(CurrentFile, PChar(Result)^, BufferSize);
  27.       Inc(NumOfCharRead, BufferSize);
  28.     end;
  29.     CloseFile(CurrentFile);    
  30.   end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement