Lazarus

Programming => General => Topic started by: Rik on December 06, 2019, 03:16:19 pm

Title: How to add Japanese characters to TComboBox.Items
Post 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
Title: Re: How to add Japanese characters to TComboBox.Items
Post by: wp on December 06, 2019, 05:28:15 pm
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.
Title: Re: How to add Japanese characters to TComboBox.Items
Post by: Rik on December 09, 2019, 09:28:11 am
selecting UTF8 did the job, thank you!

Rik
Title: Re: How to add Japanese characters to TComboBox.Items
Post by: JuhaManninen on December 09, 2019, 10:16:29 am
FYI:
 https://wiki.freepascal.org/Unicode_Support_in_Lazarus
TinyPortal © 2005-2018