2014-11-20 13:21 GMT-03:00 Mattias Gaertner <[email protected]>:

>
> Please test and tell what you find out.
>


Without {$codepage utf8} directive String constants will get Code Page 0
(CP_ACP) and not the 1200 (UTF16 - UnicodeString).

String variables assigned to those constants will also have Code Page = 0

This is because the constant string code page is evaluated at compile time

Not sure if there's a compiler command line param with same effect as
{$codepage utf8}

The attached program show how data loss can occur

Luiz
program testStringConstantCP;

{$mode objfpc}{$H+}

uses
  Classes, sysutils;
var
  W: UnicodeString;
  S, S_2: String;
  SUTF8, SUTF8_2: UTF8String;
begin
  SetMultiByteConversionCodePage(CP_UTF8);
  W := 'João';
  Write('W: ': 10, StringCodePage(W), ' - ');
  WriteLn(W);

  S := 'João';
  Write('S: ': 10,StringCodePage(S), ' - ');
  WriteLn(S);

  S_2 := W;
  Write('S_2: ': 10,StringCodePage(S_2), ' - ');
  WriteLn(S_2);

  SUTF8 := W;
  Write('SUTF8: ': 10,StringCodePage(SUTF8), ' - ');
  WriteLn(SUTF8);

  SUTF8_2 := S;
  Write('SUTF8_2: ': 10, StringCodePage(SUTF8_2), ' - ');
  WriteLn(SUTF8_2);
end.

--
_______________________________________________
Lazarus mailing list
[email protected]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply via email to