I've written a zillion bits of code that read in a text file using a loop that starts "while not eof(f) do". I had one that worked fine yesterday. Today, used to open the same file, it gives a runtime "Argument out of range" error the first time it hits the line, with the usual invitation to OK or Abort. If I choose OK it then reads the file in fine, never giving an error again despite the fact it must be checking for eof each time it goes round the loop.
And yes, it is that line. If I write:
showmessage('Check A');
while not eof(f) do
begin
showmessage('Check B');
... etc
.. then I see Check A, then the runtime error, and then as many Check B's as there are iterations of the loop.
It's perplexing. Which argument is out of range? Why has this bug suddenly arisen? What could possibly cause it?
Thanks for your help.
---
ETA: This gets weirder. Since it went wrong the first time it goes round the while loop I tried replacing it with a repeat loop, but it does the same thing — throws a runtime error when it first
enters the loop, even though I'm not performing an eof check. That is, if I put
showmessage('Check A');
repeat
showmessage('Check B');
... etc
until eof(f)
... then it produces the exact same behavior. It's just objecting to ... starting the loop? Now I feel more baffled.
What argument is out of range? There is no argument.
---
ETA2: Changed it again so the repeat loop doesn't look at eof but just stops after reading a given number of lines in. Same thing. How can
starting a loop cause a runtime error? Why is it "Argument out of range"? Am I cursed?