开发者

FormatDateTime with chinese location - wrong characters... Delphi 2007

Output: Period: from 11-Ê®¶þÔÂ-10 to 13-Ê®¶þÔÂ-10

The above output is from a line like this: FormatDateTime('dd-mmm-yy', dateValue)

The IDE is Delphi 2007 and we are trying to gear up our app to the Chinese market. How can I display the correct characte开发者_C百科rs?

With the setting turn to Hindi (India), instead of the funny characters I have the "?".

I'm trying to display the date on a report, using ReportBuilder 11.

Any help will be much appreciated.


The characters seem to be correct, only IMO they have been rendered wrong.

Here's what I've done:

  • copied the string as presented by the OP ("11-Ê®¶þÔÂ-10 to 13-Ê®¶þÔÂ-10");
  • pasted it into a blank plain-text editor window with CP 1252 (Windows Latin-1) and saved;
  • opened the text file in a browser;
  • the text showed up the same as the browser chose the same codepage, so I turned on the automatic detection of character encoding, hinting it that the contents was Chinese;
  • the text changed to "11-十二月-10 to 13-十二月-10" (hope your browser displays correct Chinese characters here, my does anyway) and the codepage changed to GB18030 (and I then tried GB2312, but the text wouldn't change);
  • well, I was curious and searched for "十二月", and it turned out to stand for "December", quite suitable for the context unless the month names had been mixed up.

So, this is why I think it's a text rendering (or whatever you call it, I'm not really sure about the term) problem.

EDIT: Of course, it must have had something to do with the data type chosen for storing the string. If the function result is AnsiString and the variable is WideString, then maybe the characters get converted as WideChars and so they are no longer one-byte compounds of multi-byte characters but are multi-byte characters on their own? At least that's what happened when the OP posted them here.

I don't know actually, but if it is so then I doubt if they can be rendered correctly unless converted back and rendered as part of an AnsiString.


Another solution is to use TntControls. They're a set of standard Delphi controls enhanced to support Unicode. You'll have to go through all your form files and replace

Button1: TButton
Label1: TLabel

with TTntButton, TTntLabel et cetera.

Please note, that as things stand, it's not only Chinese which will not work. Try any language using symbols other than standard European set (latin + stress marks etc), for instance Russian.

But

By replacing the controls, you'll solve one part of the problem. Another part is that everywhere where you use "string" or "AnsiString" and "char/pchar" or "AnsiChar/PAnsiChar", you can store only strings in default system encoding.

For instance, if your system encoding ("Language for non-unicode programs") is EN/US, Russian characters will be replaced with question marks when you assign them to "string" variable:

a: WideString;
b: string;
...
a := 'ЯУЭФЫЦ'; //WideString can store international characters
b := a; //string cannot, so the data is lost - you cannot restore it from just "b"

To store string data which is independent of system encoding, use WideString/WideChar/PWideChar and appropriate functions. If you have

a, b: WideString;
...
a := UpperCase(b);

then unicode information will still be lost because UpperCase() accepts "string":

function UpperCase(const S: string): string;

Your WideString will be converted to "string" (losing all international characters), given to UpperCase, then the result will be converted back to WideString but it's already too late.

Therefore you have to replace all string functions with Wide versions:

a := WideUpperCase(b);

(for some functions, their wide versions are unavailable or called differently, TntControls also contain a bunch of wide function versions)


The Chinese Market requires support for multi-byte character sets (either WideChar or Unicode).
The Delphi 2007 RTL/VCL only supports single-byte character sets (there is very limited support for WideChar in the RTL and VCL).

The easiest for you is to upgrade to a Delphi version that supports Unicode (Delphi 2009 was the first version that supports Unicode, the current Delphi vesion is Delphi XE).

Or you will need to update all your components to support WideChar, and rewrite the portions of RTL/VCL for which you need WideChar support.

--jeroen


  1. Did you install Far East charset support in Windows? In Windows pre 7 (or Vista) those charset are not installed by default in Western versions, you have to add them in Control Panel -> Regional Settins, IIRC
  2. Using a non-Unicode version of Delphi unluckily what character can be displayed depends on the current codepage. If it is not one of the Chinese ones, for example, it could not display the characters you need. What characters are actually displayed depends on how the codes you're using are mapped in the current codepage. You could use a multi-lingual version of Windows to switch fully to the locale you need, or you have to use a Unicode version of Delphi (from 2009 onwards).
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜