Character Set in Command Prompt Window lazarus / 61-Beginners ---------------------------------------------------------------------- Elap · 2015-08-13 17:02 I'm slowly managing to convert my TP program to FP. My next problem is that funny characters (e.g. line-drawing ones) appear OK in a WRITE statement but not in the output window when the program is run. How can a) I find what character set the IDE uses, and b) I set that for the display when the program is running? ---------------------------------------------------------------------- derek.john.evans · 2015-08-13 17:26 Ive attached a screen shot of my console with chr's 32-255 writen out. As far as I can tell, they are the same as DOS. So maybe there is another issue here. ---------------------------------------------------------------------- derek.john.evans · 2015-08-13 17:32 Its looks like this should return 437: Code: [Select]WriteLn(GetConsoleOutputCP);  If not try setting it with SetConsoleCP (**EDIT* or SetConsoleOutputCP ) ---------------------------------------------------------------------- Elap · 2015-08-13 17:36 Mine start off the same but the last few dozen are different. Oh dear... ---------------------------------------------------------------------- Elap · 2015-08-13 17:51 I've been Googling. I need the codepage to be 437. I guess this is no longer a Free Pascal question, but can one of you whizzes out there tell me how to set this permanently in a Command Prompt window (without messing around the the registry!)? ---------------------------------------------------------------------- derek.john.evans · 2015-08-13 18:08 Read up a couple of posts. I think SetConsoleOutputCP(437) is what you want, but i've read about people having problems with that. As a guide for my knowledge base. What country are you in? Strange question, but I had problems with StrToFloat() FloatToStr() at one stage because I didn't relize other countries used wacky decimals and thousands separators. Arrrr. Dam those non-english non-australia ways ---------------------------------------------------------------------- rvk · 2015-08-13 18:15 No no no... don't reset your ConsoleOutputCP yet. You're working with fp.exe in a console window, are you not? Are the lines of the windows drawn correctly??? You should wonder why... you haven't changed your ConsoleOutputCP yet so how does fp.exe do it??? I haven't checked it out thoroughly but if you look at fpc\packages\rtl-console\src\win\video.pp you'll find the following fragment: Code: [Select]  const      mapcp850 : array[0..255] of tunicodecharmapping = (        (unicode : 0; flag : umf_noinfo; reserved : 0),        (unicode : 1; flag : umf_noinfo; reserved : 0),        (unicode : 2; flag : umf_noinfo; reserved : 0),        (unicode : 3; flag : umf_noinfo; reserved : 0), And I'm wondering if that's not just the translation of the normal DOS-IBM characterset to Unicode/Utf8. So look at how you can convert your line-drawing strings to utf8 and print that to screen. ---------------------------------------------------------------------- Elap · 2015-08-13 18:26 I'm in the UK. Yes, lines get drawn correctly by fp.exe. It's the contents of the output window that don't match the contents of the Write strings. Codepages always seem to cause problems! When I was working on an international application, some of the accented characters didn't get reproduced correctly, and it was never solved by anyone by the time I retired! On reflection, what I think I need is a compiler directive that says "Use codepage 437", rather than changing the default setting for the Command Prompt window. All I want is for it to work like Turbo Pascal. ---------------------------------------------------------------------- rvk · 2015-08-13 18:42 Quote from: Elap on August 13, 2015, 08:26:20 pmOn reflection, what I think I need is a compiler directive that says "Use codepage 437", rather than changing the default setting for the Command Prompt window. For an easy fix you could do SetConsoleOutputCP(437);. It's not setting the default systemwide but the codepage for just that session. So nothing is lost. It's is the easiest way. In fact fp.exe used to do it this way too: Code: [Select]constructor TWindowsScreen.Init; var   SecurityAttr : Security_attributes;   BigWin : Coord;   res : longbool;   Error : dword;   ConsoleScreenBufferInfo : Console_screen_buffer_info; begin   inherited Init;   {if GetConsoleOutputCP<>437 then     res:=SetConsoleOutputCP(437);}   SecurityAttr.nLength:=SizeOf(Security_attributes);   SecurityAttr.lpSecurityDescriptor:=nil;   SecurityAttr.bInheritHandle:=true; See the commented lines. So you could do: Code: [Select]  if GetConsoleOutputCP<>437 then     res:=SetConsoleOutputCP(437); In the long run you might want to convert to Utf8 but in that case I think you need FPC 3 or higher (?). I'm not sure about what is in FPC 2.6.4 at the moment regarding these lines. ---------------------------------------------------------------------- Elap · 2015-08-13 18:46 SetConsoleOutputCP(437) didn't make any difference! Ho hum... ---------------------------------------------------------------------- rvk · 2015-08-13 18:59 Could you create a small test-project to show what you want to print to screen and how you're doing it? ---------------------------------------------------------------------- Elap · 2015-08-13 19:00 rvk: You were right - your Set Console thingy causes the IDE lines to be misdisplayed (if there's such a word). ---------------------------------------------------------------------- Elap · 2015-08-13 19:34 When I type the following program (the character is Alt-219), it appears as a solid rectangle. In the output window, it appears as below. program chars; uses crt; begin     clrscr;     write('Û'); end. ---------------------------------------------------------------------- rvk · 2015-08-13 19:47 What was actually your default-codepage? Code: [Select]program test; uses crt,Windows; begin  Clrscr;  Writeln(GetConsoleOutputCP);  readln; end. For me this gives a solid rectangle: Code: [Select]program test; uses crt,Windows; begin  Clrscr;  SetConsoleOutputCP(437);  //write('Û');  write(Chr(219));  readln; end. You might want to work with Chr() because in fp.exe you get Û because your default codepage is different. Or you need to set the default- codepage to 437 for your development pc. Didn't TP have a codepage setting in the Environment options somewhere? You could create a small batch file with the following: Code: [Select]chcp 437 C:\FPC\2.6.4\bin\i386-win32\fp.exe That way you'll also have the line- and blockdraw character in the ide. ---------------------------------------------------------------------- Elap · 2015-08-13 20:04 I had already created a batch file exactly the same as yours! It didn't make any difference. Writing CHR(219) doesn't make any difference either. GetConsoleOutputCP gives me 850, but even trying that still gives me the Û. There isn't an Environment setting for this in TP. ---------------------------------------------------------------------- rvk · 2015-08-13 20:42 For me (even with CP 850) it gives the block-character. What do you see in fp.exe itself? Do you see the block or the Û ? It could be, because fp.exe should be utf8 it is already saved as utf8. (but then chr(219) should have printed the block) ---------------------------------------------------------------------- Elap · 2015-08-13 20:53 The line-drawing characters in the IDE itself are fine. If I remove USES CRT the correct codepage 437 characters are displayed, but then the rest of my program is useless. Funny, huh? ---------------------------------------------------------------------- rvk · 2015-08-13 21:00 Crt.pp uses the GetACP codepage temporarily to write to the screen. So in that case you can't overrule it. What is your result of this? Code: [Select]Writeln(GetACP); Mine is 1252 (and here it also works with and without crt) ---------------------------------------------------------------------- rvk · 2015-08-13 21:07 B.T.W. did you already try this with the SuperFastConsole-unit from derek.john.evans? Maybe, because it doesn't use the conventional Write from Crt it works better. ---------------------------------------------------------------------- Elap · 2015-08-13 21:13 rvk: You're dead right. When SuperFastConsole is in the Uses clause (but not even executed!) I get the right characters. You're brilliant! ---------------------------------------------------------------------- rvk · 2015-08-13 21:17 Quote from: Elap on August 13, 2015, 11:13:38 pmWhen SuperFastConsole is in the Uses clause (but not even executed!). That's because the SuperFastConsole has an initialization-part which gets executed during program start. Quote from: Elap on August 13, 2015, 11:13:38 pmYou're brilliant! Well, much of the credit goes to derek.john.evans for creating the unit  (and you needed the unit anyways for the speed advantage )