'Delete specific record from file of records

I have the next data structure :

 Type
 TMyRecord=Record
                 Num:String[50];
                 ID:String[50];
   
 End;

and I have a file of record Like the next :

Var
F:File of TMyRecord;

the file will contains many records , how I can delete one specific record from the file.

Thank you in advance .



Solution 1:[1]

If the record is at the very end of the file, you can simply truncate the size of the file to omit the record.

Otherwise, the only way to delete a record from the beginning/middle of the file is to create a new file, copy the existing records from the old file to the new file omitting the record you want to delete, and then replace the old file with the new file.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Remy Lebeau