Assign(...) instead of AssignFile?
If it has to be old schoolI doubt that, so I show a more modern way:
Yup, something like that (missing exception handling, though?)Uhm... the only "error handling" that comes in my mind would be to test if file exists, try to delete, when that succeed write it.
And of course ;D count from zero :DAbsolute! Thats why I noted:
Ofc the record stuff I can't check but at least you see some logic.( Where I actual meant an array :-[ :-X :P )
And of course ;D count from zero :D
Me dummy, ofc it should be written like that:
for x := 1 to recds do
I believe the first answer is correct. File is closed after first x loop in the original example.Yes. 8)
Try not to close the file in your loop, does it help?
Procedure WriteVillagedata; // This will write the Data Structure to file. Var x, y : Integer; FilenameOut: TextFile; Begin Assignfile(FilenameOut, 'VillageData.txt'); Try ReWrite(FilenameOut); For x := 1 to recds do Begin WriteLn(FilenameOut, Villages[x].Name); This is line 60 as referred to in the error message. WriteLn(FilenameOut, Villages[x].Inn); WriteLn(FilenameOut, Villages[x].Government); WriteLn(FilenameOut, Villages[x].Population); WriteLn(FilenameOut, Villages[x].Families); WriteLn(FilenameOut, Villages[x].Farmers); WriteLn(FilenameOut, Villages[x].Artisans); WriteLn(FilenameOut, Villages[x].Laborers); WriteLn(FilenameOut, Villages[x].Paupers); For y := 1 to 3 do Begin WriteLn(FilenameOut, Villages[x].Gods[y]); WriteLn(FilenameOut, Villages[x].Taverns[y]); WriteLn(FilenameOut, Villages[x].Trade[y]); end; {For y} End; {For x} finally Close(FilenameOut); end; {Try} end; {Proc WriteVillagedata}
The above works, @KodeZwerg likely caught the problem, the close file being in the loop.Yes. I haven't checked it out, but I'm willing to bet it's the Close in the loop. I'm also willing to bet that the runtime error is happening during the second iteration of the x loop. Sorry guys, I just didn't notice. I had a BRAIN-FART!! When I check it tomorrow, I'm sure that will be the problem.
Maybe also his "FilenameOut" is wrong, since he not show, I added that on my own as local.No, I don't believe so. FilenameIn and FilenameOut are both declared as global variables.
I believe that you did, its just the question as what :-\Maybe also his "FilenameOut" is wrong, since he not show, I added that on my own as local.No, I don't believe so. FilenameIn and FilenameOut are both declared as global variables.
Yup, something like that (missing exception handling, though?)Uhm... the only "error handling" that comes in my mind would be to test if file exists, try to delete, when that succeed write it.
Do you have something different in your mind that I am currently not aware of?
Or you meant a seperate "try/except" around the SaveToFile() ?
As longer I think about, as more strange stuff come in my head %) (I usual just let the class do the job...)And of course ;D count from zero :DAbsolute! Thats why I noted:Ofc the record stuff I can't check but at least you see some logic.( Where I actual meant an array :-[ :-X :P )