简体   繁体   English

Delphi 7中的用户语言支持

[英]User language support in Delphi 7

My program is written in Delphi 7 and I want to avoid a Russian or a Chinese, Korean try to use my soft because file paths contains Unicode chars and my program can t handle them yet (as long as I do not port my program on a new Delphi version supporting UNICODE). 我的程序是用Delphi 7编写的,所以我想避免使用俄语或中文,韩语来尝试使用我的软件,因为文件路径包含Unicode字符,并且我的程序尚不能处理它们(只要我不将程序移植到支持UNICODE的新Delphi版本)。

How do I write a function detecting the "Unicode language" in Delphi 7? 如何在Delphi 7中编写检测“ Unicode语言”的函数?

A Delphi 7 program (in its VCL part) can handle Russian, Chinese or Korean characters without any problem. Delphi 7程序(在其VCL部分中)可以毫无问题地处理俄文,中文或韩文字符。

If the Windows system language is properly set, the charset will match the corresponding encoding, and the file names will be able to have Unicode chars as available in this charset. 如果正确设置了Windows系统语言,则字符集将与相应的编码匹配,并且文件名将能够具有此字符集中可用的Unicode字符。 In fact, default string=AnsiString is converted into Unicode when the VCL calls Windows APIs (all ....A() calls will do the conversion then call the ....W() version). 实际上,当VCL调用Windows API时,默认string=AnsiString会转换为Unicode(所有....A()调用都会进行转换,然后再调用....W()版本)。

You can force the default code page (the one which will select the charset to be used) by calling code like this : 您可以强制默认代码页通过调用代码(其中一个将选择字符集被使用) 这样的

if GetThreadLocale<>LCID then // force locale settings if different
  if SetThreadLocale(LCID) then
    GetFormatSettings; // resets all locale-specific variables

In this case, the TFileName (= AnsiString ) in the current system charset will be converted by Windows into the corresponding Unicode characters, and you'll be able to use it in your Delphi 7 application. 在这种情况下,Windows会将当前系统字符集中的TFileName (= AnsiString )转换为相应的Unicode字符,您将可以在Delphi 7应用程序中使用它。

What you can't do with the standard VCL AnsiString use it to directly mix charsets , as you can since Delphi 2009, thanks to the new string = UnicodeString default paradigm. 自从Delphi 2009以来,您可以使用标准VCL AnsiString无法使用它来直接混合字符集 ,这要归功于新的string = UnicodeString默认范例。

PS: PS:

Since the CharSet only involve #128..#255 chars (ie all with bit 7 set), if you use only #0..#127 chars, your string will be consistent whatever the current charset/codepage setting is. 由于CharSet仅包含#128 ..#255个字符(即,所有7位都已设置),因此,如果仅使用#0 ..#127个字符,则无论当前charset / codepage设置如何,字符串都将保持一致。 If you use only English chars and numbers eg, your path will always work, whatever the charset/codepage is. 例如,如果仅使用英文字符和数字,则无论字符集/代码页如何,您的路径将始终有效。 But if you use non English chars, the path will only work if the charset/codepage is correctly set, which is the case for a path used by an end-user (using a TOpenDialog at runtime for instance). 但是,如果您使用非英语字符,则只有在正确设置字符集/代码页的情况下,该路径才起作用,这是最终用户使用的路径的情况(例如,在运行时使用TOpenDialog )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM