Recent

Author Topic: Convert special characters for tables in TurboPascal  (Read 7758 times)

forbin

  • Newbie
  • Posts: 6
Convert special characters for tables in TurboPascal
« on: July 30, 2018, 03:24:38 pm »
Hello,

I've developed some Turbo Pascal DOS 7.0 using

some characters displaying tables such as :








I can't display any more the table since i convert my programs in Free Pascal.

How can i do to convert these special characters ?

Thanks

4BIN

Handoko

  • Hero Member
  • *****
  • Posts: 5131
  • My goal: build my own game engine using Lazarus
Re: Convert special characters for tables in TurboPascal
« Reply #1 on: July 30, 2018, 03:51:45 pm »
Hello forbin,
Welcome to the forum.

Ah, that are extended ASCII characters. I used them a lot.
https://theasciicode.com.ar/

I just tested this code below, it works correctly on Lazarus 1.8.4 Ubuntu 18.04:
Code: Pascal  [Select][+][-]
  1. program project1;
  2.  
  3. begin
  4.   WriteLn('┌───────┐');
  5.   WriteLn('│ HELLO │');
  6.   WriteLn('└───────┘');
  7.   ReadLn;
  8. end.
             

If you can't make it works, I think it is not Free Pascal / Lazarus issue. Can you show us your code?

Or maybe this thread can be useful for you:
https://forum.lazarus.freepascal.org/index.php/topic,41118.msg284772.html

tr_escape

  • Sr. Member
  • ****
  • Posts: 432
  • sector name toys | respect to spectre
    • Github:
Re: Convert special characters for tables in TurboPascal
« Reply #2 on: July 30, 2018, 03:53:05 pm »
Generally I am using that chars:

Courier New font in windows 7:
╔╚╝╠╣╦╩╬


You can access with by charmap.exe I didn't try in Linux desktop.

Also you can copy + paste from the editor of charmap to your software as mentioned below:

(Very simple and bad method)


Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls;
  9.  
  10. const borders='╔╚╝╠╣╦╩╬';
  11.  
  12.  
  13. type
  14.  
  15.   { TForm1 }
  16.  
  17.   TForm1 = class(TForm)
  18.     Button1: TButton;
  19.     Memo1: TMemo;
  20.     procedure Button1Click(Sender: TObject);
  21.   private
  22.  
  23.   public
  24.  
  25.   end;
  26.  
  27. var
  28.   Form1: TForm1;
  29.  
  30. implementation
  31.  
  32. {$R *.lfm}
  33.  
  34. { TForm1 }
  35.  
  36. procedure TForm1.Button1Click(Sender: TObject);
  37. var
  38.   n:Integer;
  39.   str: UnicodeString;
  40. begin
  41.   Memo1.Lines.Clear;
  42.   Memo1.Lines.Add(borders);
  43.  
  44.   Memo1.Lines.Add('');
  45.  
  46.   str:='';
  47.   for n:= $2554 to $256c do
  48.     str+=UnicodeChar(n);
  49.  
  50.   Memo1.Lines.Add(str);
  51. end;
  52.  
  53. end.
  54.  

Handoko

  • Hero Member
  • *****
  • Posts: 5131
  • My goal: build my own game engine using Lazarus
Re: Convert special characters for tables in TurboPascal
« Reply #3 on: July 30, 2018, 04:05:06 pm »
tr_escape's code worked on my test on my Linux computer. The TMemo was using the system default font.

Thaddy

  • Hero Member
  • *****
  • Posts: 14204
  • Probably until I exterminate Putin.
Re: Convert special characters for tables in TurboPascal
« Reply #4 on: July 30, 2018, 06:15:14 pm »
It depends on the codepage you are using.
Can you tell me what chcp tells you? (type chcp on the command prompt)
Specialize a type, not a var.

forbin

  • Newbie
  • Posts: 6
Re: Convert special characters for tables in TurboPascal
« Reply #5 on: August 10, 2018, 09:20:15 am »
Hi Friends,

Thanks for your kind answers !

Unfortunatly i use the FP compiler which runs under MS-DOS.

I display my program in the CMD.EXE's windows.

The trouble happens in the CMD.EXE's windows.

However one can display the table's characters through the CMD.EXE's windows.

That means that the problem comes from the translation of the character by FPC.

How to translate, that's the question  %)

Thanks

4BIN

Thaddy

  • Hero Member
  • *****
  • Posts: 14204
  • Probably until I exterminate Putin.
Re: Convert special characters for tables in TurboPascal
« Reply #6 on: August 10, 2018, 09:51:54 am »
Can you tell me what chcp does in cmd.exe?
Specialize a type, not a var.

forbin

  • Newbie
  • Posts: 6
Re: Convert special characters for tables in TurboPascal
« Reply #7 on: August 10, 2018, 12:09:15 pm »
Hi,

I've applied the following code

Code: Pascal  [Select][+][-]
  1.     program Project1;
  2.    
  3.     {$MODE OBJFPC}
  4.     {$APPTYPE CONSOLE}
  5.  
  6.     const
  7.  
  8.       C = #17#16#30#31#207#177;
  9.      
  10.     procedure Print;
  11.     var
  12.       ShortS: ShortString = C;
  13.       AnsiS: AnsiString = C;
  14.     begin
  15.       Writeln;
  16.       Writeln('ShortString = ', ShortS);
  17.       Writeln('AnsiString  = ', AnsiS);
  18.     end;
  19.      
  20.     begin
  21.       Writeln('DefaultSystemCodePage = ', DefaultSystemCodePage);
  22.       Writeln('ConsoleCodePage       = ', TextRec(Output).CodePage);
  23.       Print;
  24.       SetMultiByteConversionCodePage(TextRec(Output).CodePage);
  25.       Writeln;
  26.       Writeln('DefaultSystemCodePage = ', DefaultSystemCodePage);
  27.       Print;
  28.       Readln;
  29.     end.
  30.  
  31.  

which you've provided.

It has worked but when i tried this

Code: Pascal  [Select][+][-]
  1. PROGRAM TRYCHAR;
  2.  
  3. {$MODE OBJFPC}
  4. {$APPTYPE CONSOLE}
  5.  
  6. USES DOS, CRT, SYSUTILS;
  7.  
  8. CONST  scne=#191;
  9.        scnw=#218;
  10.        scsw=#192;
  11.        scse=#217;
  12.        slho=#196;
  13.        slve=#179;
  14.  
  15. BEGIN
  16.  
  17.   SetMultiByteConversionCodePage(TextRec(Output).CodePage);
  18.   writeln('DefaultSystemCodePage = ', DefaultSystemCodePage);
  19.   Writeln('ConsoleCodePage       = ', TextRec(Output).CodePage);
  20.  
  21.   writeln(scnw,slho,scne);
  22.   writeln(slve,' ',slve);
  23.   writeln(scsw,slho,scse);
  24.  
  25. END.
  26.  

it displayed the wrong characters and codepage 1252.

However the mode is


Statut du périphérique CON:
---------------------------
    Lignes :          9001
    Colonnes :        120
    Vitesse clavier : 31
    Délai clavier :   1
    Page de codes :   850


I understand not why the mode doesn't remain in CP850.

Thanks again for your help !

Best regards

4BIN


forbin

  • Newbie
  • Posts: 6
Re: Convert special characters for tables in TurboPascal
« Reply #8 on: August 10, 2018, 12:27:28 pm »
It seems there is a conflict with CRT unit.

When i remove CRT in the USES command it works, else not.

I unfortunately need the CRT unit.

How to reconciliate them ?

Thaddy

  • Hero Member
  • *****
  • Posts: 14204
  • Probably until I exterminate Putin.
Re: Convert special characters for tables in TurboPascal
« Reply #9 on: August 10, 2018, 01:29:09 pm »
The system code page is for your Windows GUI. The console codepage is what you need for crt.
You can try SetConsoleOutputCP under windows os's to set the actual console codepage output
Specialize a type, not a var.

forbin

  • Newbie
  • Posts: 6
Re: Convert special characters for tables in TurboPascal
« Reply #10 on: August 10, 2018, 02:02:44 pm »
Thanks but i dont know how to do it.

is SetConsoleOutputCP a Free Pascal command or should i use regedit or something else ?


Thaddy

  • Hero Member
  • *****
  • Posts: 14204
  • Probably until I exterminate Putin.
Re: Convert special characters for tables in TurboPascal
« Reply #11 on: August 10, 2018, 04:31:57 pm »
Thanks but i dont know how to do it.

is SetConsoleOutputCP a Free Pascal command or should i use regedit or something else ?
It is a function from the windows API and in winunits-base. Simply include windows in the uses clause..
Maybe this helps: http://forum.lazarus.freepascal.org/index.php/topic,38910.msg265726.html#msg265726
« Last Edit: August 10, 2018, 04:48:20 pm by Thaddy »
Specialize a type, not a var.

forbin

  • Newbie
  • Posts: 6
Re: Convert special characters for tables in TurboPascal
« Reply #12 on: August 11, 2018, 06:04:20 pm »
Many Thanks Thaddy,

I've tried

Code: Pascal  [Select][+][-]
  1. PROGRAM TRYCHAR;
  2.  
  3. {$mode objfpc}{$H+}
  4. {$APPTYPE CONSOLE}
  5.  
  6. USES {$IFDEF WINDOWS}
  7.      Windows, {for setconsoleoutputcp}
  8.      {$ENDIF} DOS, CRT;
  9.  
  10. CONST  scne=#191;
  11.        scnw=#218;
  12.        scsw=#192;
  13.        scse=#217;
  14.        slho=#196;
  15.        slve=#179;
  16.  
  17. VAR f1,f2:TEXT;
  18.  
  19. BEGIN
  20.  
  21.   {$IFDEF WINDOWS}
  22.   SetConsoleOutputCP(CP_UTF8);
  23.   {$ENDIF}
  24.  
  25.   SetMultiByteConversionCodePage(TextRec(Output).CodePage);
  26.   writeln('DefaultSystemCodePage = ', DefaultSystemCodePage);
  27.   Writeln('ConsoleCodePage       = ', TextRec(Output).CodePage);
  28.  
  29.   writeln(scnw,slho,scne);
  30.   writeln(slve,' ',slve);
  31.   writeln(scsw,slho,scse);
  32.  
  33.   Assign(f2,'OUTPUT.DAT');
  34.   Rewrite(f2);
  35.     writeln(f2,scnw,slho,scne);
  36.     writeln(f2,slve,' ',slve);
  37.     writeln(f2,scsw,slho,scse);
  38.   Close(f2);
  39.  
  40. END.
  41.  

but here is the result


DefaultSystemCodePage = 1252
ConsoleCodePage       = 1252
ÚÄ¿
³ ³
ÀÄÙ


what was wrong  :(

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: Convert special characters for tables in TurboPascal
« Reply #13 on: August 11, 2018, 11:46:14 pm »
As you have seen, adding unit CRT is causing some issues. Unit CRT is changing the console code page to ANSI:
Code: Pascal  [Select][+][-]
  1.   SetConsoleOutputCP(GetACP);

If I change your code to:
Code: Pascal  [Select][+][-]
  1. PROGRAM TRYCHAR;
  2.  
  3. {$mode objfpc}{$H+}
  4. {$APPTYPE CONSOLE}
  5.  
  6. USES {$IFDEF WINDOWS}
  7.      Windows, {for setconsoleoutputcp}
  8.      {$ENDIF} DOS
  9.      , UnicodeCRT;
  10.  
  11. CONST  scne='┐';//#191;  { use Unicode instead of ANSI }
  12.        scnw='┌';//#218;
  13.        scsw='└';//#192;
  14.        scse='┘';//#217;
  15.        slho='─';//#196;
  16.        slve='│';//#179;
  17.  
  18. VAR f1,f2:TEXT;
  19.  
  20. BEGIN
  21.   {$IFDEF WINDOWS}
  22.   SetConsoleOutputCP(CP_UTF8);
  23.   {$ENDIF}
  24.  
  25.   SetMultiByteConversionCodePage(CP_UTF8);
  26.   TextRec(Output).CodePage := CP_UTF8;
  27.   writeln('DefaultSystemCodePage = ', DefaultSystemCodePage);
  28.   Writeln('ConsoleCodePage       = ', TextRec(Output).CodePage);
  29.  
  30.   writeln(scnw,slho,scne);
  31.   writeln(slve,' ',slve);
  32.   writeln(scsw,slho,scse);
  33.  
  34.   Assign(f2,'OUTPUT.DAT');
  35.   Rewrite(f2);
  36.     writeln(f2,scnw,slho,scne);
  37.     writeln(f2,slve,' ',slve);
  38.     writeln(f2,scsw,slho,scse);
  39.   Close(f2);
  40.  
  41. END.

and change unit CRT to support Unicode, as in the attached archive, it shows the characters right as in the attached image.

Of course I had to choose a font for the console that supports Unicode.

Edit:
Unit UnicodeCRT is just a POC, it might not work properly.
« Last Edit: August 11, 2018, 11:48:41 pm by engkin »

 

TinyPortal © 2005-2018