Lazarus

Free Pascal => Beginners => Topic started by: coradi on September 17, 2021, 02:14:29 pm

Title: How can I print extended Chars like chr(205)
Post by: coradi on September 17, 2021, 02:14:29 pm
If I
write For n := 0 to 254 DO write(CHR(n));

I only get mostly normal chars, but no blocks or others
Title: Re: How can I print extended Chars like chr(205)
Post by: winni on September 17, 2021, 04:05:45 pm
Hi!

Since Lazarus has full UTFT8 support by default chars above 127 does not exist anymore .

Read:

https://wiki.lazarus.freepascal.org/Unicode_Support_in_Lazarus (https://wiki.lazarus.freepascal.org/Unicode_Support_in_Lazarus)

Unicode and UTF8 are more than 20 years old. Time to get informed.

Winni

Title: Re: How can I print extended Chars like chr(205)
Post by: ASerge on September 17, 2021, 09:46:57 pm
I only get mostly normal chars, but no blocks or others
It depends on the console settings.
Program below print blocks on my console:
Code: Pascal  [Select][+][-]
  1. {$MODE OBJFPC}
  2. {$APPTYPE CONSOLE}
  3.  
  4. var
  5.   C: AnsiChar;
  6. begin
  7.   for C in AnsiChar do
  8.     Write(C);
  9.   Readln;
  10. end.
Title: Re: How can I print extended Chars like chr(205)
Post by: BobDog on September 18, 2021, 10:54:34 am

The default codepage here is 850, I get the extended asci characters.
So change codepage (temporary)
Code: Pascal  [Select][+][-]
  1. program codepage;
  2.   function  system(s:pchar):integer ; cdecl external 'msvcrt.dll' name 'system';
  3. var
  4. n:integer ;
  5. begin
  6.  
  7. system('CHCP 850');
  8.  
  9. for n:=0 to 255 do write(char(n));
  10. writeln;
  11. readln;
  12. end.
Title: Re: How can I print extended Chars like chr(205)
Post by: Thaddy on September 18, 2021, 12:15:11 pm
Or without msvcrt:
Code: Pascal  [Select][+][-]
  1. {$MODE OBJFPC}
  2. {$APPTYPE CONSOLE}
  3. uses process;
  4. var
  5.   P:TProcess;
  6.   C: AnsiChar;
  7. begin
  8.    P:=TProcess.create(nil);
  9.    P.Executable := 'C:\Windows\SysWOW64\chcp.com'; // on most systems
  10.    P.Parameters.Add('850');
  11.    P.Execute;
  12.    P.Free;  
  13.    for C in AnsiChar do
  14.     Write(C);
  15.   Readln;
  16. end.
Title: Re: How can I print extended Chars like chr(205)
Post by: MarkMLl on September 18, 2021, 12:33:39 pm
Unicode and UTF8 are more than 20 years old. Time to get informed.

OP doesn't say that he's using Lazarus, and in the absence of a compilable example appears to be asking about single characters rather than strings.

Does FPC have the equivalent of

Code: Pascal  [Select][+][-]
  1. type
  2.   UTF8String = type AnsiString(CP_UTF8);
  3.  

etc. for single characters?

MarkMLl
Title: Re: How can I print extended Chars like chr(205)
Post by: BobDog on September 18, 2021, 12:54:24 pm
Or without msvcrt:
Code: Pascal  [Select][+][-]
  1. {$MODE OBJFPC}
  2. {$APPTYPE CONSOLE}
  3. uses process;
  4. var
  5.   P:TProcess;
  6.   C: AnsiChar;
  7. begin
  8.    P:=TProcess.create(nil);
  9.    P.Executable := 'C:\Windows\SysWOW64\chcp.com'; // on most systems
  10.    P.Parameters.Add('850');
  11.    P.Execute;
  12.    P.Free;  
  13.    for C in AnsiChar do
  14.     Write(C);
  15.   Readln;
  16. end.

Without msvcrt I could do
Code: Pascal  [Select][+][-]
  1. program codepage;
  2. uses process;
  3.  
  4. var
  5. n:integer ;
  6. s:ansistring;
  7. begin
  8. RunCommand('CHCP.com 850',s);
  9. writeln(s);
  10.  
  11. for n:=0 to 255 do write(char(n));
  12. writeln;
  13. readln;
  14. end.

But the compiler reminds me:
Warning: Symbol "RunCommand" is deprecated
Title: Re: How can I print extended Chars like chr(205)
Post by: Thaddy on September 18, 2021, 02:01:59 pm
Yes, deprecated, so I used the - recommended - Tprocess.
Title: Re: How can I print extended Chars like chr(205)
Post by: marcov on September 18, 2021, 02:46:51 pm
Yes, deprecated, so I used the - recommended - Tprocess.

It is that specific variant of runcommand that is deprecated, which is obvious since that line doesn't separate exe and arguments out. IOW this is the runcommand equivalentof the commandline vs parameters.add difference.

So the proper way would be

Code: Pascal  [Select][+][-]
  1. runcommand('chcp.com',['850']);



Title: Re: How can I print extended Chars like chr(205)
Post by: BobDog on September 18, 2021, 04:35:13 pm

The deprecated way is good IMO, the ansistring parameter accepts the console out, like a pipe.
The other method (runcommand('chcp.com',['850'])) gives an error here:
Error: Call by var for arg no. 2 has to match exactly: Got "{Array Of Const/Constant Open} Array of Constant String" expected "AnsiString"
I am using an ide for version 3.2.2 64 bits, not lazarus.





Title: Re: How can I print extended Chars like chr(205)
Post by: coradi on September 18, 2021, 04:45:32 pm
this is what I get with the dll and Codepage 850
Title: Re: How can I print extended Chars like chr(205)
Post by: BobDog on September 18, 2021, 04:59:15 pm

Hi coradi,
That doesn't look too good.
I get
Active code page: 850

 ☺☻♥♦♣
♫☼►◄↕‼¶§▬↨↑↓→←∟↔▲▼ !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~⌂ÇüéâäàåçêëèïîìÄÅÉæÆôöòûùÿÖÜø£Ø׃áíóúñѪº¿®¬½¼¡«»░▒▓│┤ÁÂÀ©╣║╗╝¢¥┐└┴┬├─┼ãÃ╚╔╩╦╠═╬¤ðÐÊËÈıÍÎÏ┘┌█▄¦Ì▀ÓßÔÒõÕµþÞÚÛÙýݯ´­±‗¾¶§÷¸°¨·¹³²■ 


Could it be your system locale?
Try some other codepages maybe?
I use Win 10 which has a powerful console mechanism for showing different characters.
Title: Re: How can I print extended Chars like chr(205)
Post by: Jurassic Pork on September 18, 2021, 06:00:37 pm
hello coradi,
what is your cmd console font (right click / properties / font tab) ?
Friendly, J.P
Title: Re: How can I print extended Chars like chr(205)
Post by: coradi on September 19, 2021, 08:30:29 am
is the same. font:-(
TinyPortal © 2005-2018