[fpc-devel] TRegistry and Unicode

Bart bartjunk64 at gmail.com
Thu Mar 7 19:11:54 CET 2019


On Thu, Mar 7, 2019 at 6:30 PM Yuriy Sydorov <jura at cp-lab.com> wrote:

> Of course if "u8" is utf8string, then then first char will be encoded as a 2-byte pair. But if you change "u8" to be
> just "string" or "ansistring", then the first byte would contain "รค" if the current ansi code page supports it (eg cp1252).
> It is perfectly backward compatible.

Sorry, wrong example.
Querying the result without assigning it to a variable will fail (I
tried to say that in my previous post):

program test;

function x: utf8string;
var
  u: unicodestring;
begin
  setlength(u,3);
  //00E4 00EB 00EF
  word(u[1]) := $E4;
  word(u[2]) := $EB;
  word(u[3]) := $EF;
  result := utf8encode(u);
end;

begin
  if byte(x[1]) = $E4 then writeln('OK') else writeln('Fail');
end.

This would have written OK if x (e,g, TRegistry.ReadString()) returned
string instead of UTF8String.

-- 
Bart



More information about the fpc-devel mailing list