EOF Problem lazarus / 21-General ---------------------------------------------------------------------- J-G · 2025-04-27 18:29 As you'll have gathered, I'm not doing much coding at the moment but the 'problem' that I asked about in January has reared its head. A reminder - I have an old customer with a very old PC which 'Died' taking his Garage business database out. It was running a DOS program so there was no Mouse support and writing a Windows program was not viable - even though I did go through the motions. He brought me a 'backup' PC  which was running Win 98 but didn't have a COM Port mouse, No PS/2 port . . . . . Long Story  -  now short . . . .   I've at least 'Resurected' it (I've actually named it 'Lazarus'! )  Installed a PCI card with PS/2 & USB along with a copy of Win XP  -  It's now fully operational and I have run the Pascal program on it. NOW  -  He was hoping to re-install his old program probably running in a DOS Window but the 'Master' discs that he has are only a [Demo] version. So I offered to extract his 'Products' file from the Backup Data that he did have - (I'd already extracted Names etc. & Vehicles) This was going very well but out of the blue I'm getting a 103 File not Open error  -  this is with the Name & Address File which had been working perfectly  -  -  Stepping through, I can see that the file 'Opens' -  ie. IOResult returns zero,  but when it should then read the file until EOF it skips to 'Close File' (jumps from line 5 to 12) and returns the 103 when I try to execute line 12. Two bits of code -  the first is the assignment and opening and the second is the Reading : Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   Assign(NAD_FIle,datapath+'LeekNAD.DAT');  {$I-} Reset(NAD_file); {$I+}  I := IOResult;  If I = 0  then    begin      Read_NAD_File;    end  else Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   procedure Read_NAD_File;  begin    SetLength(NAD,20);    n :=1;    while not EOF do      begin        read(NAD_File,NAD[n]);        inc(n);        if n > length(NAD)-1          then SetLength(NAD,Length(NAD)+20);      end;    close(NAD_File);  end;  Nothing extraordinary and I've just checked the Vehicles file and that's doing the same !!!!!    Both .DAT files have been in use since they were created in January and I've also re-created them from the original .DBF files. Can anyone suggest what I might have done to upset the applecart? ---------------------------------------------------------------------- MarkMLl · 2025-04-27 18:38 You either need to reset the file with an explicit record length, or declare it as "file of" an appropriately-declared record, or if you've told Reset() that the record length is 1 byte then use BlockRead() with an appropriate count parameter. By default, the record size is documented as 128 bytes which is a hangover from CP/M-80 days. https://www.freepascal.org/docs- html/current/rtl/system/filefunctions.html If you really do know the format, defining a record of that type then double-checking its size and using "file of" would be the preferred "old school" way of doing it. MarkMLl ---------------------------------------------------------------------- J-G · 2025-04-27 18:49 Thanks for the swift response Mark but I think you've missed the point that these files have been working perfectly for quite some time. The variables in use are Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   NAD_File : File of Customer;  NAD        : Array of Customer;  NAD_Length : Word;   VEH_File   : File of Vehicle;  VEH        : Array of Vehicle;  VEH_Length : Word;   PROD_File  : File of Product;  PROD       : Array of Product;  PROD_Length: Word;  with the 'Customer', 'Vehicle' & 'Product' all being fully defined 'Records'. Yes I do know the precise structure of the .DBF files as well. I'm just adding the [Product] to what was a fully operational program and I haven't modified any of the code that reads (or rather doesn't!) the Customer or Vehicle files. ---------------------------------------------------------------------- jamie · 2025-04-27 19:01 yours EOF check isn't checking the file handle, its defaulting to keyboard in etc. you need EOF(NAD_File) ,,,,, ---------------------------------------------------------------------- J-G · 2025-04-27 19:20 Quote from: jamie on April 27, 2025, 09:01:52 pmyours EOF check isn't checking the file handle, its defaulting to keyboard in etc. you need EOF(NAD_File) ,,,,, Jamie  !!!  -  Thanks     I knew it just needed a decerning 'Eye' over it  How it has worked for the past months is beyond my comprehension but I'm sure that there is likely to be a rational explanation. I can't even fathom 'when' it changed or what I did - it worked this morning - - -   and is now working again. I'm very grateful. ---------------------------------------------------------------------- ASerge · 2025-04-28 18:57 Quote from: J-G on April 27, 2025, 09:20:05 pm...and is now working again. And this? Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i  SetLength(NAD,20);    n :=1; // Must be zero !!!    while not EOF(NAD_File) do      begin        read(NAD_File,NAD[n]);          inc(n);        if n > length(NAD)-1 // better n >= length(NAD)        then SetLength(NAD,Length(NAD)+20); ---------------------------------------------------------------------- OC DelGuy · 2025-04-28 19:38 Quote from: jamie on April 27, 2025, 09:01:52 pmyours EOF check isn't checking the file handle, its defaulting to keyboard in etc. you need EOF(NAD_File) ,,,,, I saw that!  I don't have anything to add, but I'm proud of myself that I actually saw the problem and knew the fix!    Even the little things excite me! Having said that... Quote from: J-G on April 27, 2025, 09:20:05 pmHow it has worked for the past months is beyond my comprehension but I'm sure that there is likely to be a rational explanation. I can't even fathom 'when' it changed or what I did - it worked this morning - - -   and is now working again. I'm very grateful. What DID change?  Why did it work for months and then...  Not?     (Assuming no one changed the program.) Just curious