Jackets Jackets - 3 years ago 256
Pascal Question

How can I write to the beginning of a file and insert rather than overwrite data?

Is there a way in Pascal to write to the start of a file, without overwriting other data?

I have learnt

Seek(F, 0);
but this overwrites the first thing in the file.

Answer Source

You may achieve your goal with the following algorithm:

  • Create temporary file;
  • Write your new data to this temporary file;
  • Read all data from target file and append them to temporary file;
  • Rename temporary file to target one;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download