I thought I might be able to assign a unicode string (WideString) to a
normal TLabel with:
label1.Caption := UTF8ToAnsi(UTF8Encode(WS));
and it would show correctly. All it shows is '?????????'.
Why doesn't this work?
Is there any combination of functions I can use to get this to work?
Thanks
Rael
> label1.Caption := UTF8ToAnsi(UTF8Encode(WS));
>
> and it would show correctly. All it shows is '?????????'.
>
> Why doesn't this work?
> Is there any combination of functions I can use to get this to work?
I can only guess here, but if the WideString contains characters that
do not exist in the code page that you are using then they cannot be
encoded in your ansi string and are replaced with a marker character.
This should be fairly easy to check by looking at the intermediate
results.
If you want to display Unicode you have 4 options:
* Wait for the next release of Delphi (aka Tiburon)
* Use Delphi.NET which is already unicode enabled
* Use controls that are Unicode enabled (something like the TNT
controls)
* Bypass the VCL and use the Windows Unicode APIs to set the control
properties and/or do your own painting.
--
Marc Rohloff [TeamB]
marc -at- marc rohloff -dot- com
Hey,
A normal TLabel is not working with Unicode. Try to set the
CharSet-Property to the correct Language-Setting. I did that with our
Language-Translator to support Chinese, Russian, Greek and Polish
settings. That should help for you too. (almost) a quick and dirty
solution :-D
But take care that the operating system is working with the charset. I
had problems with an german XP switched to polish settings for example.
Not all characters were translated correct. You should use a native OS
for the language (Polish OS with Polish language settings) to get a
proper translation.
I think the problem is that polish is not the same CharSet-Code that the
OS has (Germany is ANSI_CHARSET and Poland is EASTEUROPE_CHARSET)
Here a little bit of code from me.
function BestimmeCharset (Laendercode : ShortString) : Smallint;
begin
Result := DEFAULT_CHARSET;
if (SameText (Laendercode, 'en') = True) or
(SameText (Laendercode, 'de') = True) or
(SameText (Laendercode, 'at') = True) or
(SameText (Laendercode, 'ch') = True) or
(SameText (Laendercode, 'nl') = True) or
(SameText (Laendercode, 'fr') = True) or
(SameText (Laendercode, 'no') = True) or
(SameText (Laendercode, 'it') = True) then
begin
Result := ANSI_CHARSET;
end;
if (SameText (Laendercode, 'ru') = True) or
(SameText (Laendercode, 'uk') = True) then
begin
Result := RUSSIAN_CHARSET;
end;
if (SameText (Laendercode, 'el') = True) then
begin
Result := GREEK_CHARSET;
end;
if (SameText (Laendercode, 'zh') = True) or
(SameText (Laendercode, 'zh.tra') = True) then
begin
Result := CHINESEBIG5_CHARSET;
end;
if (SameText (Laendercode, 'pl') = True) or
(SameText (Laendercode, 'ro') = True) then
begin
Result := EASTEUROPE_CHARSET;
end;
if (Result = DEFAULT_CHARSET) then
begin
Result := Result; // no Translation were made. Only for debugging
end;
{
ANSI_CHARSET 0 ANSI-Zeichen.
DEFAULT_CHARSET 1 Die Schriftart wird nur anhand von Name
und Größe gewählt. Wenn die angegebene Schriftart nicht verfügbar ist,
verwendet Windows eine andere Schriftart.
SYMBOL_CHARSET 2 Standardsymbolsatz.
MAC_CHARSET 77 Macintosh-Zeichen. Nicht in NT 3.51 verfügbar.
SHIFTJIS_CHARSET 128 Japanische Shift-JIS-Zeichen.
HANGEUL_CHARSET 129 Koreanische Zeichen (Wansung).
JOHAB_CHARSET 130 Koreanische Zeichen (Johab). Nicht in NT
3.51 verfügbar.
GB2312_CHARSET 134 Vereinfachte chinesische Zeichen (VRC).
CHINESEBIG5_CHARSET 136 Traditionelle chinesische Zeichen (Taiwan).
GREEK_CHARSET 161 Griechische Zeichen. Nicht in NT 3.51
verfügbar.
TURKISH_CHARSET 162 Türkische Zeichen. Nicht in NT 3.51 verfügbar.
VIETNAMESE_CHARSET 163 Vietnamesische Zeichen. Nicht in NT 3.51
verfügbar.
HEBREW_CHARSET 177 Hebräische Zeichen. Nicht in NT 3.51
verfügbar.
ARABIC_CHARSET 178 Arabische Zeichen. Nicht in NT 3.51 verfügbar.
BALTIC_CHARSET 186 Baltische Zeichen. Nicht in NT 3.51 verfügbar.
RUSSIAN_CHARSET 204 Kyrillische Zeichen. Nicht in NT 3.51
verfügbar.
THAI_CHARSET 222 Thailändische Zeichen. Nicht in NT 3.51
verfügbar.
EASTEUROPE_CHARSET 238 Enthält diakritische Zeichen für
osteuropäische Länder. Nicht in NT 3.51 verfügbar.
OEM_CHARSET 255 Von der Codeseite des Betriebssystems abhängig
ISO-Bereiche:
-1 Latin-1, Westeuropäisch
-2 Latin-2, Mitteleuropäisch
-3 Latin-3, Südeuropäisch
-4 Latin-4, Baltisch
-5 Kyrillisch
-6 Arabisch
-7 Griechisch
-8 Hebräisch
-9 Latin-5, Türkisch
-10 Latin-6, Nordisch
-11 Thai
-13 Latin-7, Baltisch
-14 Latin-8, Keltisch
-15 Latin-9, Westeuropäisch
-16 Latin-10, Südosteuropäisch
}
end;
HTH
Chris