* * *

Author Topic: Unit CRT changes the ASCII character set  (Read 765 times)

Vampirro

  • Newbie
  • Posts: 3
Unit CRT changes the ASCII character set
« on: December 06, 2016, 08:49:06 am »
Hi,

This is my first post and I'm sorry about my poor English.

Well, I have to make an old fashioned DOS application for Windows, with the ▒╣ and similar characters to create windows. But when I use the CRT unit for using colours, gotoxy and so on the character set changes to CP-1252. I've tried to print all the ASCII character set but these characters (▒╣╩╦) have gone. I've tried to use UTF-8 with

Code: Pascal  [Select]
  1. write (utf8ToAnsi('░'));

But the result is the character '¦' (the same with ▒,▓...)

How can I resolve this problem? Thanks for all

Vampirro

  • Newbie
  • Posts: 3
Re: Unit CRT changes the ASCII character set
« Reply #1 on: December 06, 2016, 12:05:53 pm »
I don't know if it's important, but... I have Windows 10. This code:

Code: Pascal  [Select]
  1. program ascii;
  2.  
  3. begin
  4.     writeln(chr(176));
  5. end.
  6.  

prints "░" in screen, but this one:

Code: Pascal  [Select]
  1. program ascii;
  2.  
  3. uses crt;
  4.  
  5. begin
  6.     writeln(chr(176));
  7. end.
  8.  

prints this character "°". Why? How can I continue using the "non-CRT" characters with the crt functions and procedures?

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 5338
Re: Unit CRT changes the ASCII character set
« Reply #2 on: December 06, 2016, 01:06:38 pm »
Windows has three character encodings:

- Unicode, which is UTF16 for unicode characters
- ansi, which is a collective name for various 8-bit encodings (including utf-8 in the few places where Windows uses it)
- oem, the dos-like codepage from the console.

Constants are ansi, but you want to print OEM. The conversion function is ansitooem (which is nowadays implemented using chartooem). CRT takes over the console and probably does this automatically (?)

Another thing to try is changing the OEM codepage from the default 850 to ancient default dos with

chcp 437

before running your program.
« Last Edit: December 06, 2016, 01:08:10 pm by marcov »

Vampirro

  • Newbie
  • Posts: 3
Re: Unit CRT changes the ASCII character set
« Reply #3 on: December 06, 2016, 07:04:18 pm »
Thanks!

But... I'm not used to code in Pascal. I'm looking for an example of CharToOemBuff function in a Free Pascal program but I cannot find it. Could you give me an example, please?

Thanks for all

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus