SetThreadLocale for the entire Delphi application

試著忘記壹切 提交于 2019-12-02 02:12:08

问题


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?


回答1:


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!