Recent

Author Topic: How can I print extended Chars like chr(205)  (Read 2424 times)

coradi

  • Full Member
  • ***
  • Posts: 148
How can I print extended Chars like chr(205)
« 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
« Last Edit: September 17, 2021, 02:17:01 pm by coradi »
Amstrad Schneider CPC 6128
AVR8/ARM(STM32)

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: How can I print extended Chars like chr(205)
« Reply #1 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

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

Winni


ASerge

  • Hero Member
  • *****
  • Posts: 2212
Re: How can I print extended Chars like chr(205)
« Reply #2 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.

BobDog

  • Sr. Member
  • ****
  • Posts: 394
Re: How can I print extended Chars like chr(205)
« Reply #3 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.

Thaddy

  • Hero Member
  • *****
  • Posts: 14157
  • Probably until I exterminate Putin.
Re: How can I print extended Chars like chr(205)
« Reply #4 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.
Specialize a type, not a var.

MarkMLl

  • Hero Member
  • *****
  • Posts: 6646
Re: How can I print extended Chars like chr(205)
« Reply #5 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
« Last Edit: September 18, 2021, 05:08:18 pm by MarkMLl »
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

BobDog

  • Sr. Member
  • ****
  • Posts: 394
Re: How can I print extended Chars like chr(205)
« Reply #6 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

Thaddy

  • Hero Member
  • *****
  • Posts: 14157
  • Probably until I exterminate Putin.
Re: How can I print extended Chars like chr(205)
« Reply #7 on: September 18, 2021, 02:01:59 pm »
Yes, deprecated, so I used the - recommended - Tprocess.
Specialize a type, not a var.

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11351
  • FPC developer.
Re: How can I print extended Chars like chr(205)
« Reply #8 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']);




BobDog

  • Sr. Member
  • ****
  • Posts: 394
Re: How can I print extended Chars like chr(205)
« Reply #9 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.






coradi

  • Full Member
  • ***
  • Posts: 148
Re: How can I print extended Chars like chr(205)
« Reply #10 on: September 18, 2021, 04:45:32 pm »
this is what I get with the dll and Codepage 850
Amstrad Schneider CPC 6128
AVR8/ARM(STM32)

BobDog

  • Sr. Member
  • ****
  • Posts: 394
Re: How can I print extended Chars like chr(205)
« Reply #11 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.

Jurassic Pork

  • Hero Member
  • *****
  • Posts: 1228
Re: How can I print extended Chars like chr(205)
« Reply #12 on: September 18, 2021, 06:00:37 pm »
hello coradi,
what is your cmd console font (right click / properties / font tab) ?
Friendly, J.P
« Last Edit: September 18, 2021, 06:06:55 pm by Jurassic Pork »
Jurassic computer : Sinclair ZX81 - Zilog Z80A à 3,25 MHz - RAM 1 Ko - ROM 8 Ko

coradi

  • Full Member
  • ***
  • Posts: 148
Re: How can I print extended Chars like chr(205)
« Reply #13 on: September 19, 2021, 08:30:29 am »
is the same. font:-(
Amstrad Schneider CPC 6128
AVR8/ARM(STM32)

 

TinyPortal © 2005-2018