RunError(123) when writing to File lazarus / 13-General ---------------------------------------------------------------------- Lalaji · 2013-05-26 19:02 Hello folks, I have been around for a few months, finally got stuck enough to register and ask for help. I need to write an array into a Text File. I am doing this with several arrays in several parts of the program, but for some reason this gives me an error. The code I am using is as follows: Code: [Select]begin   ...   WriteTempRoomsArr('C:\TempArr.txt');   ... end; program WriteTempRoomsArr(FileLoc: String); var   F: TextFile;   x: Integer; begin   AssignFile(F, FileLoc);   {$I-}     Write(F); // I tried write and ReWrite. Got the same error.   {$I+}   for x := 1 to High(TempRoomsArr) do// Is not a dynamic array, is defines from [1..68]   begin     WriteLn(F, TempRoomsArr[x].String);// <- I get the error here.     ...   end;   CloseFile(F); end; The error I am getting is "Project raised an exception class 'RunError(123)'. I am using: Lazarus version: 1.0.1 FPC Version: 2.6.0 Debugging on Win Xp SP3 32-Bit I tried to look up the error, dont know where it originates from or what it indicates. I am looking for any help I can get. Thank you for your time. Lalaji ---------------------------------------------------------------------- taazz · 2013-05-26 20:21 1) the correct command to open a file for write is Rewrite not write. 2) a fast grep on my fpc directory finds 762 lines which have 123. The most interesting is the file errors.inc in the \rtl\win\wininc folder which line reads Code: [Select]     ERROR_INVALID_NAME                           = 123; ---------------------------------------------------------------------- Lalaji · 2013-05-26 20:46 Thanks for the response Taazz, I first did try ReWrite, then Write they both gave me the same error.  Invalid Name? Like the file name? I dont see what could be wrong with that. Can you please tell me how you looked up the error, like where did you search for it to find the 762 line? Again, thanks. ---------------------------------------------------------------------- taazz · 2013-05-26 21:03 in lazarus go to menu "Search\Find in Files..." on the dialog that open select "search in directories" and on the directory options select the fpc installation directory in my case that is "C:\lazarus.1.0\fpc\".  I can't comment on the problem you are having with out the actual filename that raises the error, I asume that there are spaces in the filename you are trying to open or something along those lines. in any case why don't you try to use a TFlieStream instead, it is much more powerful and has better support. ---------------------------------------------------------------------- Bart · 2013-05-26 21:31 You use {$I-} to disable IO checking, but you never check if Rewrite fails. If it does, then InOutRes will be 0, and the next IO operation will fail. So you see the error on the line that does the actual writing, but the actual error may be on the line with rewrite. That does not explain the RTE number 123, but I merely want to point out you might be looking at the wrong line of code. Do something like this: Code: [Select]var   DosError: Integer; begin   AssignFile(F, FileLoc);   {$I-}     Rewrite(F);     DosErros := IOResult; //calling IOResult clear the InOutRes variable, so save it     if DosError <> 0 then     begin       writeln('Error creating file, ErrorCode = ',DosError);       Exit;     end;   {$I+}   .... end; Bart ---------------------------------------------------------------------- Bart · 2013-05-26 21:33 Also it seems kind of strange that the reserved word program shows up in the middle of your code? Bart ---------------------------------------------------------------------- Bart · 2013-05-26 21:50 Quote from: Lalaji on May 26, 2013, 09:02:42 pmCode: [Select]     WriteLn(F, TempRoomsArr[x].String);// <- I get the error here. That will not even compile at all. A record field cannot be named String, it can only be of type String. And another warning. Thanks to modern Windows behaving like a virus (it says files exist, but they don't and the other way around, it says you wrote to a file, but the file does not exist) writing to C:\TempArr.txt fails on my Win7 (invoking as normal user), without any failure code. The program runs "fine", but it does not create the requested file. Thank you very much MicroSuck. Bart ---------------------------------------------------------------------- User137 · 2013-05-26 23:44 That is compiler inconsistency is it not? String can't be variable name but integer can  This compiles: Code: [Select]procedure TForm1.Button1Click(Sender: TObject); var integer: string; begin   integer:='1';   caption:=integer; end; For original problem, print out the filename to be sure. Are there any non A..Z characters? ---------------------------------------------------------------------- Lalaji · 2013-05-27 02:41 Bart and User137, I very much appreciate the responces! Quote from: Bart on May 26, 2013, 11:33:56 pmAlso it seems kind of strange that the reserved word program shows up in the middle of your code? Bart Bart, you sir have a very keen eye! My coding computer is not connected to Internet (I broke the adapter ), so I am having to check the forums on this other computer. In the process of retyping the code on this computer, I mis-typed. That is supposed to be Procedure not Program. Sorry for the confusion. Quote from: Bart on May 26, 2013, 11:50:04 pmQuote from: Lalaji on May 26, 2013, 09:02:42 pmCode: [Select]     WriteLn(F, TempRoomsArr[x].String);// <- I get the error here. That will not even compile at all. A record field cannot be named String, it can only be of type String. Bart Let me elaborate: TempRoomsArr is a [1..68] array of TRoom. TRoom is defined to have a property "String", which in fact is a string. Compiles fine for me.  I dont know what caused the issue, but I averted it by loading the array onto a TStringsList and the useing the SaveToFile Procedure. Thank you all for the help Lalaji ---------------------------------------------------------------------- User137 · 2013-05-27 03:12 Quote from: Lalaji on May 27, 2013, 04:41:45 amTRoom is defined to have a property "String", which in fact is a string. Compiles fine for me.  You should change that. Even if it works now, it will break after you update Lazarus. ---------------------------------------------------------------------- BigChimp · 2013-05-27 05:24 Quote from: Bart on May 26, 2013, 11:50:04 pmThanks to modern Windows behaving like a virus (it says files exist, but they don't and the other way around, it says you wrote to a file, but the file does not exist) writing to C:\TempArr.txt fails on my Win7 (invoking as normal user), without any failure code. The program runs "fine", but it does not create the requested file. Thank you very much MicroSuck. If you don't want file redirection or UAC, switch it off. However, if you would like to have secure programs that do what "Microsuck" have been asking devs to do for the last 10 years or so, write to the correct directories. (And yes, it's nasty that they did this file redirection trick but it does work for backward compatibility) My 2 cents.