[Lazarus] Garbage writing to console

Luca Olivetti luca at wetron.es
Thu Feb 22 13:46:14 CET 2018


El 22/02/18 a les 13:07, Tony Whyman via Lazarus ha escrit:
> You may find the "SetTextCodePage" procedure useful when it comes to 
> setting the code page for a Windows console.
> 
> e.g. SetTextCodePage(stdout,cp_utf8);

Same result: garbage with writeln, correct result with w


> 
> See also 
> https://www.freepascal.org/docs-html/rtl/system/settextcodepage.html
> 
> 
> On 22/02/18 11:21, Luca Olivetti via Lazarus wrote:
>> Lazarus 1.8.0, fpc 3.0.4, windows application (with "win32 gui 
>> application unchecked") or console application (using LazUTF8).
>> File encoding utf-8 without bom.
>>
>> writeln('áéí')
>>
>> produces garbage, contrary to what's said in 
>> http://wiki.freepascal.org/Unicode_Support_in_Lazarus#Writing_to_console
>>
>> using {$codepage utf8} (or utf-8 with bom) fixes it, but I'm not sure 
>> it's recommended to do so: 
>> http://wiki.freepascal.org/Unicode_Support_in_Lazarus#String_Literals
>>
>> The strange thing is that:
>>
>> procedure w(const s:string);
>> begin
>>   writeln(s);
>> end;
>>
>> w('áéí')
>>
>>
>> also gives the correct output.
>> Why? After all I'm using the same string literal.
>> I suppose there's some underlying automatic conversion going on, but 
>> it's very confusing.
>>
>> Bye
> 


-- 
Luca Olivetti
Wetron Automation Technology http://www.wetron.es/
Tel. +34 93 5883004 (Ext.3010)  Fax +34 93 5883007


More information about the Lazarus mailing list