Forum > Beginners

How to display non ASCII characters in Lazarus console?

(1/2) > >>

Blancheflor:
Hello everyone, I'm new to Lazarus and Free Pascal, I need your help!
I used first the FPC editor (without Lazarus) which can display without problems my accents in the console but when I changed to Lazarus, all the non-ASCII characters are displayed strangely in the console. I tried to understand how to fix it but the wiki is too technical and the examples in the forum don't work for me or I don't understand what I should try from the code examples. Here is what I wrote in Lazarus:

--- Code: ---program Project1;
var
  Txt1 : widestring;
  Txt2 : Utf8String;
begin
  txt1 :='é';
  txt2 :='à';
  writeln(txt1);
  writeln;
  writeln(txt2);
  readln();
end.
                 
--- End code ---

But the console displays 2 strange characters instead. Can someone tell me how to correct this program to display these characters in the console? I'm using the latest Lazarus(32bits)/FPC versions and Windows 7 64 bits. Thanks in advance for your help! :)

howardpc:
Make sure the LCL is added as a dependency for your project and try this:


--- Code: ---program Project1;

{$mode objfpc}{$H+}

uses LazUTF8;

var
  Txt1 : string;
  Txt2 : string;
begin
  txt1 :='éééééééééé';
  txt2 :='àààààààààà';
  writeln(UTF8ToConsole(Txt1));
  writeln;
  writeln(UTF8ToConsole(Txt2));
  readln();
end.

--- End code ---

Blancheflor:
Thank you Howard, it works, here's a magic chocolate box for you! :)

if chocolatepieces := 0 then chocolatepieces := +1;

As usual I copy-pasted the code without thinking and it gave me a dependency error message, then I saw your line and found the dependency and added it*. This was the only thing annoying me in the console so I can continue to learn the basics.

*If you are stuck here too, click Project in the menu bar then Project Inspector/Add/New Condition, in Package Name drop down list type "LazUtils" then click Create New Requirement.

Bart:

--- Quote from: Blancheflor on October 18, 2014, 08:52:54 pm ---if chocolatepieces := 0 then chocolatepieces := +1;

--- End quote ---

That won't compile  O:-)

Bart

Blancheflor:

--- Quote from: Bart on October 19, 2014, 12:29:35 am ---
--- Quote from: Blancheflor on October 18, 2014, 08:52:54 pm ---if chocolatepieces := 0 then chocolatepieces := +1;

--- End quote ---

That won't compile  O:-)

Bart

--- End quote ---

Ok, for you then, this took me ages and almost destroyed my brain %) :


--- Code: ---program magic_box;
uses
  crt;
var
  choco: integer;
  answer: string;

begin
  choco := 3;
  while choco > 0 do
  begin
  writeln('Your box contains ', choco, '. Do you want to eat a chocolate piece? y/n ');
  readln(answer);
  if answer = 'y' then
  choco := choco -1
  else if answer = 'n' then
  writeln('you hypocrite!');
  end;
  writeln('Your box contains ', choco, ' chocolate pieces :-(');
  writeln;
  writeln('Ok stop crying... Do you believe in magick? y/n' );
  readln(answer);
if answer = 'y' then
begin
choco := choco +1;
  writeln('Your faith in magick has saved your stomach, wait while I summon the delicacy');
   delay (1000);
  write ('Abra...');
   delay (1000);
   write('ca...');
   delay (1000);
   write('da...');
   delay (1000);
   writeln('bra...');
   writeln('Your box contains now ', choco, ' chocolate piece!');
  end
  else if answer ='n' then
  writeln('No chocolate for you then, you unfaithful one!');
  readkey;
 end.

--- End code ---

Navigation

[0] Message Index

[#] Next page

Go to full version