Advertisement
believe_me

Untitled

May 18th, 2022
2,127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. procedure removeDeleters();
  2. const
  3.     TEMP_FILE_NAME = 'TempFile.bin';
  4. var
  5.     SourceFile, TempFile: TBinaryFile;
  6.     OneByte: ansichar;
  7.     BufferArray: Array[1..ONLY_DATA_SIZE] of ansichar;
  8.     offset: integer;
  9.     Number: longWord;
  10. begin
  11.     assign(SourceFile, GetCurrentDir + '\' + FILE_NAME);
  12.     assign(TempFile, GetCurrentDir + '\' + TEMP_FILE_NAME);
  13.     Number := 0;
  14.     rewrite(TempFile);
  15.     reset(SourceFile);
  16.     offset := START_SUBSCRIBER_OFFSET;
  17.     while not EOF(SourceFile) do
  18.     begin
  19.         blockRead(SourceFile, OneByte, 1);
  20.         if (OneByte <> DELETER) then
  21.         begin
  22.             Seek(SourceFile, Offset + NUMBER_LENGTH);
  23.             blockRead(SourceFile, BufferArray, ONLY_DATA_SIZE);
  24.             blockWrite(TempFile, Number, NUMBER_LENGTH);
  25.             blockWrite(TempFile,  BufferArray, ONLY_DATA_SIZE);
  26.             inc(Number);
  27.         end;
  28.         Offset := Offset + RECORD_SIZE;
  29.         seek(SourceFile, Offset);
  30.     end;
  31.     closeFile(SourceFile);
  32.     closeFile(TempFile);
  33.     deleteFile(GetCurrentDir + '\' + FILE_NAME);
  34.     RenameFile(GetCurrentDir + '\' + TEMP_FILE_NAME, GetCurrentDir + '\' + FILE_NAME);
  35. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement