Lazarus
Programming => General => Topic started by: Rik on December 06, 2019, 03:16:19 pm
-
Using the Object Inspector I can add Japanese characters to a ComboBox (eg '㋉ ㋊ ㋋ ㋜ ㋞').
But if I try to do this at runtime it fails:
MyBox.Items.Add('㋉ ㋊ ㋋ ㋜ ㋞'); // MyBox = TComboBox
results in "ã ã ã ã " in the ComboBox.
Via a unicode string the result is the same:
tmp:= '㋉ ㋊ ㋋ ㋜ ㋞'; // tmp = UnicodeString
MyBox.Items.Add(tmp); // MyBox = TComboBox
I assume this happens because Items.Add expects a string not a UnicodeString.
How can I solve this?
Rik
-
Inserting the literal string works for me correctly (Laz trunk/fpc 3.04, Laz 3.02/fpc 3.04, Laz 1.4.4/fpc 2.6.4) - see first line in attached screenshot. Please check that the encoding of the source file is UTF8 (right-click in source editor on your file, select "FileSettings" > "Encoding" > "UTF8" must be selected).
Assigning the unicodestring to the listbox item does not work correctly (last line in screenshot). But this is expected - the LCL works with UTF8-encoded strings. Just declare your strings as "string", not "UnicodeString" (this is something else; these two-bytes-per-codepoint strings are used by Delphi), and you will not have any encoding issues most of the time. (2nd line in the screenshot).
P.S.
I hope that you are working with an fpc version 3.0 or later; in older versions string handling is a bit more difficult.
-
selecting UTF8 did the job, thank you!
Rik
-
FYI:
https://wiki.freepascal.org/Unicode_Support_in_Lazarus