[Lazarus] WinCE and strings

Felipe Monteiro de Carvalho felipemonteiro.carvalho at gmail.com
Tue Jul 10 13:25:04 CEST 2012


Well, look here:

   Msg2 := SysToUTF8('Texte message'+#13#10+'çàéioù');

You have text in UTF-8, and then you use the routine SysToUTF8 to
convert it from system encoding to utf-8, which makes no sense. It
should be like this:

   Msg2 := 'Texte message'+#13#10+'çàéioù';

Without any conversion. The same in the line with AnsiToUTF8. Now
about the unicode, there are also errors:

   Msg3 := UnicodeString('Texte message'+#13#10+'çàéioù');
   LabelInfo.Caption := Msg3;
   MessageDlg('Unicode',Msg3, mtError, [mbOK], 0, mbOK);

You have a UTF-8 string and then you make a cast to UnicodeString.
Unless you install a Lazarus widestring manager, FPC will make an
automatic conversion system encoding to UTF-16. Which is wrong. The
best is to make everything explicit, without relying in those hidden
conversions, like this:

   Msg3 := UTF8ToUTF16('Texte message'+#13#10+'çàéioù');
   LabelInfo.Caption := UTF16ToUTF8(Msg3);
   MessageDlg('Unicode', UTF16ToUTF8(Msg3), mtError, [mbOK], 0, mbOK);

Felipe




More information about the Lazarus mailing list