Recent

Author Topic: can writeln output null terminated wide character arrays ?  (Read 2435 times)

440bx

  • Hero Member
  • *****
  • Posts: 4031
can writeln output null terminated wide character arrays ?
« on: July 09, 2018, 04:45:48 am »
Hello,

The following works fine

Code: Pascal  [Select][+][-]
  1. var
  2.    anarrowstring : pchar = 'this is a "narrow" string';
  3. ...
  4. begin
  5.    writeln(anarrowstring);
  6. end.
  7.  
The compiler is, as expected, perfectly happy with that.  On the other hand, if pchar is changed to pwidechar, the compiler emits an error stating that variables of that type can neither be read nor written.  e,g.  the following does not work :


Code: Pascal  [Select][+][-]
  1. var
  2.    awidestring : pwidechar = 'this is a "wide" string';
  3. ...
  4. begin
  5.    writeln(awidestring);
  6. end.
  7.  

Did I miss something or is it really the case that writeln cannot write wide characters to the console ?   I can always import wprintf from user32.dll but, I'd rather keep things "pascal" if possible.

Thank you for your help.

(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

Thaddy

  • Hero Member
  • *****
  • Posts: 14373
  • Sensorship about opinions does not belong here.
Re: can writeln output null terminated wide character arrays ?
« Reply #1 on: July 09, 2018, 07:05:09 am »
Cast to unicodestring?

Code: Pascal  [Select][+][-]
  1. program untitled;
  2. var
  3.    awidestring : pwidechar = 'this is a "wide" string';
  4.  
  5. begin
  6.    writeln(unicodestring(awidestring));
  7. end.
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

440bx

  • Hero Member
  • *****
  • Posts: 4031
Re: can writeln output null terminated wide character arrays ?
« Reply #2 on: July 09, 2018, 06:19:44 pm »
That works :D.  Thank you Thaddy.
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

 

TinyPortal © 2005-2018