I assume cus_file is a typed file of TRecord.
Seek(f, x), where f is a typed file of record, moves the file pointer to the xth record in the file. If you use FileSize for x you will move it way beyond the end of the file (unless the record size is only one byte)!
I am wondering about the Seek(f,FileSize(f)) command. Now, I guess things can change in the 33 years or so since it was published, but in the "TURBO Pascal Reference Manual" on Page 95 of the
www.retroarchive.org/docs/tp3/tp3_14-16.pdf , for Seek it states,
Seek moves the file pointer is moved to the n'th component of the file denoted by FilVar. n is an integer expression. The position of the first component is 0. Note that in order to expand a file it is possible to seek one component beyond the last component. The statement Seek(FilVar, FileSize(FilVar)); thus places the file pointer at the end of the file (FileSize returns the number of components in the file, and as the components are numbered from zero, the returned number is one greater than the number of the last component.)
So in the past I've used the Seek(f,FileSize(f)) with Turbo Pascal without problem. But now, using this more modern Freepascal version, there seems to be a difference in how FileSize works? The manual states "n'th component of the file."
In the
www.freepascal.org documentation, it states "Filesize returns the total number of records in the file F. In cannot be invoked with a file of type Text." So it also states "records" which I equate with "components" as in Turbo Pascal, but yet, I get an error(#217 I think) attempting to append a file in this manner.
Also, as a long-ago user of Turbo Pascal but a newbie with this, I don't remember ever having to use FileUtil.FileSize(f), it was always just FileSize(f).
One last question was what the FileMode=2 does, as I don't remember that either.
Thanks for any/all help.
I'm hoping this is somewhat like riding a bicycle, without the falling off part of course.