SetThreadLocale为整个Delphi应用程序 [英] SetThreadLocale for the entire Delphi application

查看:266
本文介绍了SetThreadLocale为整个Delphi应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Delphi(XE 10)程序使用nonunicode(单字节)旧Firebird数据库(字符集NONE),因此其数据(从数据库中读取或保存到数据库中)取决于非Unicode程序的Windows Locale。根据此Windows设置,程序中可以显示相同的数据库字符为\\\ā(正确)或\\\в(不正确)。 IBX用作数据库访问技术。



我的程序仅适用于非Unicode程序的特定本地程序,这对于客户端是可以接受的。问题是 - 无论Windows设置如何让程序感觉到特定的预定义语言环境?



我想我应该使用 SetThreadLocale 为此。但是在哪里放这个电话?在主窗体的初始化部分调用这个函数是足够的,或者我应该在项目源文件(应用程序被初始化的时候)调用它,或者我应该调用它在每个模块的初始化部分?



由于我的意见,我被意识到 GetThreadLocale返回与GetUserDefaultLCID不同的值?
我现在看到我应该写更多的代码:

  SetThreadLocale(my_preferred_locale_id); 
SysLocale.DefaultLCID:= my_preferred_locale_id;
GetFormatSettings;

但主要问题仍然是 - 在哪里放这个代码 - 我应该把它放在多个地方。我有WebSnap应用程序,我猜想它可以在引擎盖下自动和复杂的胎面管理。代码应该去哪里?



没有帮助:




  • 添加lc_ctype = WIN1257 TIBDatabase.Params

  • 设置SetThreadLocale ...在这里,无处不在

  • 设置项目选项 - 版本信息 - 语言 - 区域设置ID



https:// github .com / xupefei / Locale-Emulator Locale Emulator是解决问题的唯一工具,但为什么Delphi不允许在没有外部工具的情况下执行此操作?

解决方案

正如我也发布在Firebird支持邮件列表(好奇地,海报有不同的名称,但同样的问题):



对我来说,除了使用NONE的数据库外,您也可以连接字符集NONE。为了解决这个问题,明确指出lc_ctype = win1257应该是足够的。



我不太熟悉Delphi,但假设Delphi内部使用unicode,那么它应该可以工作。 / p>

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.

这篇关于SetThreadLocale为整个Delphi应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆