Recent

Author Topic: How to add Japanese characters to TComboBox.Items  (Read 3046 times)

Rik

  • Jr. Member
  • **
  • Posts: 67
How to add Japanese characters to TComboBox.Items
« 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

wp

  • Hero Member
  • *****
  • Posts: 11853
Re: How to add Japanese characters to TComboBox.Items
« Reply #1 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.

Rik

  • Jr. Member
  • **
  • Posts: 67
Re: How to add Japanese characters to TComboBox.Items
« Reply #2 on: December 09, 2019, 09:28:11 am »
selecting UTF8 did the job, thank you!

Rik

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4459
  • I like bugs.
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

 

TinyPortal © 2005-2018