Search code examples
delphiunicodefreepascallazarus

Lazarus. Equivalent to Chr() for Unicode symbols


Is there any function in freepascal to show the Unicode symbol by its code (e.g. U+1D15E)? Unfortunately Chr() works only with ANSI symbols (with codes less than 127).
I want to use symbols from custom symbolic font and it is very inconvenient to put them into sourcecode directly (they are shown in Lazarus as ? or something else because they are absent in system fonts).


Solution

  • Take a look at this page. I assume that Freepascal either uses UTF-16, in which it becomes a surrogate pair of two WideChars (see table) or UTF-8, in which it becomes a sequence of byte values (see table again).

    UTF-8:

    const
      HalfNoteString = UTF8String(#$F0#$9D#$85#$9E);
    

    UTF-16:

    const
      HalfNoteString = UnicodeString(#$D834#$DD5E);
    

    The names of the string types may differ, as I don't know FreePascal very well. Perhaps AnsiString and WideString.