Unable to generate files in user dir lazarus / 34-Windows ---------------------------------------------------------------------- JuergenE · 2014-06-01 16:32 Hello lazarus forum members, I am an embedded engineer and want to write a tool for embedded engineering with windows 8 64 bit running lazarus 1.2.2. I need to store project data and decided to use a ini file for that. I wrote a small procedure to generate an empty ini file in case of project file does not exist. The issue is that the software stops with runtime error 3 in the line try Rewrite(MyTextFile); if the location is a user dir. Everything works fine in other directories. Some examples: // Error 3: // ProjectSettings.ProjectFolder:= 'C:\Users\Jürgen\Documents\Dropbox\ Stahlwille\BG_Debugger\testproject'; // ProjectSettings.ProjectFolder:= 'C:\Benutzer\Jürgen\Dokumente'; // ProjectSettings.ProjectFolder:= 'C:\Users\Jürgen\Documents';  // Works fine: // ProjectSettings.ProjectFolder := 'C:\ProgramData\Fips_BG_Debugger\MyProjects'; // ProjectSettings.ProjectFolder := 'C:\Temp'; Unfortunately it is a too hard restriction to disallow the user directories for project data :-(. This is the function I used to generate the project file:   procedure GenerateNewProjetFile;   var MytextFile: Textfile;   begin     AssignFile(MyTextFile, IniFilename);     try Rewrite(MyTextFile);       Writeln(MyTextFile, '[General]');       Writeln(MyTextFile, '[Timer]');       Writeln(MyTextFile, '[DAQ]');       ShowMessage(InfoString1);     except       ShowMessage(ErrorString1);     end;     CloseFile(MyTextFile);   end;                    Thanks in advance for the help! ---------------------------------------------------------------------- marcov · 2014-06-01 16:35 Juergen has an umlaut.  Do you pass the umlaut in ANSI encoding to FPC routines, or in UTF8? For FPC 2.6.x it should be ANSI, not UTF8 ---------------------------------------------------------------------- Bart · 2014-06-01 17:21 This directory 'C:\Benutzer\Jürgen\Dokumente' will not exist. It is the "pretty name" that Explorer shows you, but on disk it's real name will be  'C:\Users\Jürgen\Documents'. Bart ---------------------------------------------------------------------- tr_escape · 2014-06-01 18:39 Actually this message dont releated topic but i want to share... https://laurelrusswurm.files.wordpress.com/2012/07/restricted- boots.jpg ---------------------------------------------------------------------- JuergenE · 2014-06-01 19:08 Hello marcov, hello Bart, thanks for the hints. The "umlaut" is defenitely the root cause of my issue. I added a new user named "test" and with that user everything was fine. @Bart: I tried the "nice name" and the real name with the same result. @marcov: Can you give a short hint how to control the string encoding? Currently there is an edit field as source for the string transferred to the write procedure. The string from the edit field is stored in that record: type ProjectSettingsT = record     ProjectFolder:     String;     ProjectName:       String;     MapFile:           String;    ... end;  The edit field can be filled manually or with the standard windows file open dialog. Jürgen ---------------------------------------------------------------------- Bart · 2014-06-01 20:34 Are you using Lazarus or just freepascal? If the former, then take a look at the LazFileUtf8Classes unit. Bart ---------------------------------------------------------------------- JuergenE · 2014-06-01 21:08 I use Lazarus. I will try than unit tomorrow evening. Thanks, Jürgen ---------------------------------------------------------------------- Bart · 2014-06-01 21:45 In that case use TFileStreamUTF8 to create files. It expects filename in UTF8 (default encoding in Lazarus) and will create the file, whether or not the filename has codepoints outside current codepage (e.g. chinese characters). Use ForceDirectoriesUtf8 to create the directory. Bart ---------------------------------------------------------------------- JuergenE · 2014-06-02 20:11 Hello Bart, hello marcov, thanks a lot, the issue is solved!  I simply added a UTF8ToAnsi() to convert the strings before passing them to RTL functions. E.g.: AssignFile(MyTextFile, UTF8ToAnsi(IniFilename)); I wish you a nice week. Jürgen ---------------------------------------------------------------------- Bart · 2014-06-02 21:54 You must be aware that this (Utf8ToAnsi) will fail if the filename contains any character outside the current windows codepage. Probably this does not effect your code, but some user with a russian username for instance were to use your program, it would certainly fail. This failure would not occur if you would use the dedicated UTF8 filefunctions from LazFileUtils unit (since they directly use the WideString versions of the win API). Bart