Getting the current encoding lazarus / 7-LCL ---------------------------------------------------------------------- tech-pro · 2008-11-05 09:48 I am trying to take advantage of the UTF8 support in the latest Lazarus but for compatibility reasons I need to convert the entered text into an 8-bit representation. Therefore I need to know the encoding that is used so that I can call the appropriate UTF8Toxxxx function in unit LConvEncoding. The function GetSystemEncoding appears to return the default encoding method for the system, which I presume is by design since there is no description of the function in the documentation. This falls down if you use the Language Bar in Windows (I don't know if Linux has similar functionality.) If I switch to say a Russian keyboard the function still reports the encoding on my system as 'cp1252'. It seems to me that there needs to be a GetCurrentEncoding function, or something like that, but perhaps I am missing something? ---------------------------------------------------------------------- Phil · 2008-11-05 14:18 Quote from: "tech-pro"The function GetSystemEncoding appears to return the default encoding method for the system, which I presume is by design since there is no description of the function in the documentation. On Windows, GetSystemEncoding uses the Win API function GetACP. On non-Windows, GetSystemEncoding uses a variety of environment variables, none of which will be set on OS X. Don't know about Linux. Thanks. -Phil ---------------------------------------------------------------------- tech-pro · 2008-11-05 17:43 On Windows, GetSystemEncoding reports 'cp1252'. On my Linux system it reports 'ansi'. I'm not sure what I'm supposed to do with that. In the keyboard section of the control panel the character set is selected as ISO-8859-1'. That does not appear in any environment variable I can see, so there appears to be no way for a program to find it out. I guess it is yet another example of how Linux has not been properly thought out. However, Linux users are pretty used to working around stuff like this. I have added a setting to my program to allow the character encoding to be specified. It's up to the user to make it match what they are using. I would have thought that under Windows there was a way for a program to find out the character set being used if changed on the fly from the taskbar, but I'm not up on API stuff to know how to do it. Probably no-one is going to be changing the language on the fly other than me, who was doing it just to see how the program would handle non-English characters. ---------------------------------------------------------------------- Phil · 2008-11-05 18:30 Quote from: "tech-pro"On Windows, GetSystemEncoding reports 'cp1252'. On my Linux system it reports 'ansi'. I'm not sure what I'm supposed to do with that. In the keyboard section of the control panel the character set is selected as ISO-8859-1'. That does not appear in any environment variable I can see, so there appears to be no way for a program to find it out. I guess it is yet another example of how Linux has not been properly thought out. However, Linux users are pretty used to working around stuff like this. I have added a setting to my program to allow the character encoding to be specified. It's up to the user to make it match what they are using. I would have thought that under Windows there was a way for a program to find out the character set being used if changed on the fly from the taskbar, but I'm not up on API stuff to know how to do it. Probably no-one is going to be changing the language on the fly other than me, who was doing it just to see how the program would handle non-English characters. Here's a bug report that I filed that has some very useful feedback from Laz/FPC authors: http://bugs.freepascal.org/view.php?id=12198 Maybe you can for now adapt the approach that Jonas suggests. Thanks. -Phil