0

How do I write Unicode characters in a console window? I've Googled and the most common answer is either use UTF8String or set the Codepage using SetConsoleOutputCP but I can't get it to work! The Danish letter ø isn't displaying correctly.

I DID read this question: Is Writeln capable of supporting Unicode? and I DID try out the code before posting my own question.

A little test program:

program Project1;

{$APPTYPE CONSOLE}
{$R *.res}

uses
  System.SysUtils, Winapi.Windows;

var
  HolidayName: String;
begin
  HolidayName := 'Palmesøndag'; // Palm Sunday in Danish
  Writeln(HolidayName);
  Writeln(UTF8String(HolidayName));
  SetConsoleOutputCP(TEncoding.UTF8.CodePage);
  Writeln(HolidayName);
  Readln;
end.

And the result is:

enter image description here

So in short what am I doing wrong?

jkdev
  • 11,360
  • 15
  • 54
  • 77
Jens Borrisholt
  • 6,174
  • 1
  • 33
  • 67
  • I succeeded in getting the desired display by using Lucida Console font (which caused the first two lines to be correct) and changing `TEncoding.UTF8.CodePage` to `CP_UTF8` which fixed the third line. – Magoo Apr 14 '19 at 12:28
  • @Jens, did you select a font that is unicode compliant ( for example Lucida Console or Consolas)? – LU RD Apr 14 '19 at 12:42
  • No I'll try that later. I just wondered why it works in c# but not in Delphi – Jens Borrisholt Apr 14 '19 at 13:57

0 Answers0