On Mon, Aug 1, 2011 at 3:09 AM, Reinier Olislagers <reinierolislag...@gmail.com> wrote: > (Reposted from the forum) > > I tried to output Unicode text to console on English Windows Vista > (using Lucida Console font, which shows Greek and Cyrillic characters). > Doesn't seem to work. > (On Debian x64 it works perfectly - maybe because the default encoding > I've got is UTF8: LANG environment variable is en_US.utf8?) > If I redirect the output to file, I can see the output properly for the > output containing "plain" if I open the file as UTF8. > > Does anybody know how to do this? > > Thanks, > Reinier > > {$mode objfpc}{$H+} > program UnicodeTest; > > uses > {$IFDEF UNIX} > {$IFDEF UseCThreads} > cthreads, > {$ENDIF} > {Widestring manager needed for widestring support} > cwstring, > {$ENDIF} > Classes, > StrUtils > ; > > var > UTF8TestString: string; > OurWideString: widestring; > begin > UTF8TestString:= ' rosé, водка and ούζο'; > writeln ('plain: ' + UTF8TestString); > writeln (UTF8ToANSI('utf8toansi: ' + UTF8TestString)); > writeln (UTF8Decode('utf8decode: ' + UTF8TestString)); > //Just for luck, shouldn't work: > writeln (ANSIToUTF8('ansitoutf8: ' + UTF8TestString)); > writeln (UTF8Encode('utf8encode: ' + UTF8TestString)); > writeln (''); > OurWideString:= 'rosé, водка and ούζο'; > writeln ('plain: ' + OurWideString); > writeln (UTF8ToANSI('utf8toansi: ' + OurWideString)); > writeln (UTF8Decode('utf8decode: ' + OurWideString)); > //Just for luck, shouldn't work: > writeln (UTF8Encode('utf8encode: ' + OurWideString)); > writeln (ANSIToUTF8('ansitoutf8: ' + OurWideString)); > end.
In console programs, try UTF8ToConsole() function (unit FileUtil). A string "created" outside of your code, use SysToUTF8() to convert in a UTF8 and after UTF8ToConsole() to print on the console. Marcos Douglas _______________________________________________ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal