My Delphi (XE 10) program uses nonunicode (single byte) legacy Firebird database (character set NONE) and therefore its data (that are read from or saved into database) depends on the windows Locale for the nonunicode programs. Depending on this Windows setting the same database character can be displayed in the program as \u0101 (that is correct) or \u0432 (that is not correct). IBX serves as DB access technology.
My program works only for the specificed local for nonunicode programs and that is acceptable for the client. The question is - how can I make program to feel the specific predefined locale regardless of the Windows settings?
I guess that I should use SetThreadLocale
for this. But where to put this call? Is it sufficient to call this function in the initialization section of the Main form or should I call it in the project source file (where application is initialized) or maybe I should call it in the initialization sections of each module?
Owing to comments I was made aware of GetThreadLocale returns different value than GetUserDefaultLCID? I now see that I should write a bit more code:
SetThreadLocale(my_preferred_locale_id);
SysLocale.DefaultLCID := my_preferred_locale_id;
GetFormatSettings;
But the main question still remains - where to put this code - should I put it into multiple places. I have WebSnap application and I guess that it can have automatic and complex tread management under the hood. Where code should go?
Nothing helps:
- adding lc_ctype=WIN1257 to TIBDatabase.Params
- setting SetThreadLocale... here, there and everywhere
- setting Project Options - Version Info - Language - Locale ID
https://github.com/xupefei/Locale-Emulator Locale Emulator is the only tool that solves the problem but why Delphi does not allow to do this without external tool?
As I also posted on the Firebird-support mailing list (curiously the poster there had a different name, but the same problem):
It sounds to me like apart from your database using NONE, you also connect with character set NONE. To solve this, explicitly specifying lc_ctype = win1257 should be enough.
I don't know Delphi well enough, but assuming Delphi internally uses unicode, then it should work.
来源:https://stackoverflow.com/questions/42154760/setthreadlocale-for-the-entire-delphi-application