spu*_*eon 6 delphi unicode dll localization
我在UI上错误地显示Unicode字符时遇到问题.我有一个资源专用DLL包含用于UI本地化的字符串表.我在Delphi XE3中创建了DLL,只有一个DLL项目(只有{$R 'lang.res' 'lang.rc'}
在DPR文件中,并给我lang.dll
).我已经验证我的lang.rc文件是UTF-8格式,带有Windows CRLF换行符.当我从DLL加载字符串时,Unicode字符在界面上混乱.这是一些细节.
字符串表中的一个片段:
STRINGTABLE
{
59,"180?"
60,"90? CW"
61,"90? CCW"
}
Run Code Online (Sandbox Code Playgroud)
以下是代码片段,说明了我对Unicode字符的问题:
// explicitly assigning the degrees character shows 180? properly
ImageMenu180Action.Caption := '180?';
// getting the resource from the DLL shows some weird two-character string for the degrees character
ImageMenu90CWAction.Caption := TLangHelper.LoadStr(IDS_ImageMenuRotationCW90);
// OutputDebugString shows the degrees character in the debugger output correctly
OutputDebugString(PChar('IDS_ImageMenuRotationCW90: '+TLangHelper.LoadStr(IDS_ImageMenuRotationCW90)));
Run Code Online (Sandbox Code Playgroud)
这是我的Delphi函数,用于从资源DLL加载字符串:
class function TLangHelper.LoadStr(ResourceId: Integer):String;
var
Buff: String;
L: Integer;
begin
Result := '';
if LangDllHandle = 0 then begin
LangDllHandle := LoadLibrary(LANGUAGE_DLL_LOCATION);
if LangDllHandle = 0 then begin
ShowMessage('Error loading language localization resources.');
end;
end;
if LangDllHandle <> 0 then begin
L := 1024;
SetLength(Buff, L+1);
LoadString(LangDllHandle, ResourceId, PChar(Buff), L);
Result := String(PChar(Buff));
end;
end;
Run Code Online (Sandbox Code Playgroud)
有什么建议?
跟进:
对于中文字符,我必须在.rc文件中的字符串定义中添加前面的L,以便DLL编译将它们识别为Unicode.例如(英文,繁体中文,简体中文,法文):
STRINGTABLE
{
35,"Status Bar"
1035,L"???"
2035,L"???"
3035,"Barre d'état"
}
Run Code Online (Sandbox Code Playgroud)
我从2002年找到了一个引用,表明你需要告诉资源编译器.rc文件是如何编码的.对于UTF-8,这是代码页65001,所以你运行这个:
brcc32 -c65001 lang.rc
然后,当然,您'lang.rc'
将从$R
代码中的指令中删除该部分,因为您不再希望IDE调用资源编译器本身.
如果您的Delphi版本足够新,那么您可以保留完整$R
指令,而是-c65001
在项目选项的资源编译器配置中设置选项.
通过查看它很难知道文件的编码.可以有许多有效的猜测.该-c
选项被记录,但该文件没有提到当你需要使用它,或者当IDE使用什么它运行资源编译器.IDE可能只使用默认值,与brcc32.exe相同,后者是系统的默认ANSI代码页.
归档时间: |
|
查看次数: |
1254 次 |
最近记录: |