Recent

Author Topic: Constructing a string of Unicode characters [SOLVED]  (Read 4878 times)

carl_caulkett

  • Sr. Member
  • ****
  • Posts: 306
Constructing a string of Unicode characters [SOLVED]
« on: June 27, 2017, 05:00:14 pm »
Lazarus 1.6.4
FPC 3.0.2
macOS 10.12.5 Sierra

Hello, I want to construct a string containing several instances of the Unicode equivalent to the old Box Drawing character Ascii code (196). I want to display the string in a TListView which on the Apple Mac defaults to using the Lucida Grande font.

I have discovered that the Unicode code for the wide line character that I want is 2500, but the problem is that the command I would normally use, namely, the StringOfChar statement only returns an AnsiString. How can I build a string of Unicode wide line characters?

Thanks,
Carl
« Last Edit: June 27, 2017, 11:25:34 pm by carl_caulkett »
"It builds... ship it!"

Mac Mini M1
macOS 13.6 Ventura
Lazarus 2.2.6 (release version)
FPC 3.2.2 (release version)

Thaddy

  • Hero Member
  • *****
  • Posts: 14159
  • Probably until I exterminate Putin.
Re: Constructing a string of Unicode characters
« Reply #1 on: June 27, 2017, 05:40:14 pm »
You do not explain WHAT type of unicode. In UTF8 old code should work. #2500 is UTF16-LE, not UTF8. Try {$mode delphiunicode}
Specialize a type, not a var.

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: Constructing a string of Unicode characters
« Reply #2 on: June 27, 2017, 06:07:51 pm »
You can do something like this:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormCreate(Sender: TObject);
  2. const
  3.   Long_Line = '─';
  4. var
  5.   li: TListItem;
  6.   i: Integer;
  7. begin
  8.   ListView1.Font.Name:='Lucida Bright';
  9.   li:=ListView1.Items.Add;
  10.   li.Caption:='';
  11.   for i:=0 to 19 do begin
  12.     li.Caption:=li.Caption+Long_Line;
  13.   end;
  14. end;

carl_caulkett

  • Sr. Member
  • ****
  • Posts: 306
Re: Constructing a string of Unicode characters
« Reply #3 on: June 27, 2017, 09:55:50 pm »
I just get a string of â characters. In my case, I had to use Font.Name:='Lucida Grande'; because the Lucida Bright font is not on my computer.

I should also point out that I am using the TListView in virtual mode, the data coming from a TcaUnicodeStringlist class I have written which only deals with UnicodeStrings - no AnsiStrings whatsoever.
« Last Edit: June 27, 2017, 09:59:00 pm by carl_caulkett »
"It builds... ship it!"

Mac Mini M1
macOS 13.6 Ventura
Lazarus 2.2.6 (release version)
FPC 3.2.2 (release version)

Thaddy

  • Hero Member
  • *****
  • Posts: 14159
  • Probably until I exterminate Putin.
Re: Constructing a string of Unicode characters
« Reply #4 on: June 27, 2017, 10:08:42 pm »
the data coming from a TcaUnicodeStringlist class I have written which only deals with UnicodeStrings - no AnsiStrings whatsoever.
UTF8(bytes vary from 1 to 4) ? UTF16 (full, bytes vary from 2 to 4)? UTF16-LE (partially, Delphi style, bytes fixed at two)?, UTF32 (bytes fixed at four) ?
What kind of Unicode? We can't help you when we don't know. Unicode on its own means nothing.

If you mean the FPC (not Lazarus) supported UnicodeString type (UTF16-LE) , you also need a unicode16 capable font.

This should work, though:
Code: Pascal  [Select][+][-]
  1. var
  2.   a: UnicodeChar = #2500;
  3.  
provided the font supports it. And the console supports unicode16.
« Last Edit: June 27, 2017, 10:37:01 pm by Thaddy »
Specialize a type, not a var.

carl_caulkett

  • Sr. Member
  • ****
  • Posts: 306
Re: Constructing a string of Unicode characters [SOLVED]
« Reply #5 on: June 27, 2017, 11:25:14 pm »
Of course, when I read that the character I want has a code of 2500, it would help me no end if I took notice of whether that code was in decimal or hex. I tried it with $2500 and the default font and it works perfectly.

Nonetheless, I know I'm still quite inexperienced with Unicode (all flavours!) but I can't help feeling that it's a bit of a mess and way more complicated than it needs to be.
"It builds... ship it!"

Mac Mini M1
macOS 13.6 Ventura
Lazarus 2.2.6 (release version)
FPC 3.2.2 (release version)

Remy Lebeau

  • Hero Member
  • *****
  • Posts: 1311
    • Lebeau Software
Re: Constructing a string of Unicode characters [SOLVED]
« Reply #6 on: June 29, 2017, 01:41:23 am »
Of course, when I read that the character I want has a code of 2500, it would help me no end if I took notice of whether that code was in decimal or hex. I tried it with $2500 and the default font and it works perfectly.

Unicode codepoints (not codes!) are usually expressed in hex with a "U+" prefix.  So, what you are really working with is Unicode codepoint U+2500 DRAWINGS LIGHT HORIZONTAL, which is expressed as $2500 or #9472 in code that works with Unicode characters, or as $C4 or #196 in code that works with Extended ASCII characters.
« Last Edit: June 29, 2017, 01:44:07 am by Remy Lebeau »
Remy Lebeau
Lebeau Software - Owner, Developer
Internet Direct (Indy) - Admin, Developer (Support forum)

 

TinyPortal © 2005-2018