Delphi 2009 RawByteString vagaries

Suppose for some vicious reason you want to display the contents of the original byte of UTF8String.

var
  utf8Str : UTF8String;
begin    
  utf8Str := '€ąćęłńóśźż';
end;

(1) This does not happen; it displays a readable form:

memo1.Lines.Add( RawByteString( utf8Str ));
// output: '€ąćęłńóśźż'

(2) This, however, "works" - note the concatenation:

memo1.Lines.Add( 'x' + RawByteString( utf8Str ));
// output: 'x€ąćęłńóśźż'

I understand (1), although forcing the compiler to UnicodeString does not seem to allow RawByteString var as-is to be displayed. However, why the behavior change in (2)?

(3) Stranger - cancel concatenation:

memo1.Lines.Add( RawByteString( utf8Str ) + 'x' ); 
// output: '€ąćęłńóśźżx'

I read new line types in Delphi and thought I understood how they work, but this is a mystery.

+5
source share
2

RawByteString , , AnsiString .

RawByteString. . . , , :

  • ( )
  • , , StringCodePage.

, , StringCodePage RawByteString . , AnsiString, , .

, , undefined. RTM Update 2, RTL , , . , , .

+9

TMemo " ". - Unicode, , TMemo Delphi 2009.

, UTF8String 1252, :

var
  utf8Str : UTF8String;
  Raw: RawByteString;
begin
  utf8Str := '€ąćęłńóśźż';
  Raw := utf8Str;
  SetCodePage(Raw, 1252, False);
  Memo.Lines.Add(Raw);
end;

. RawByteString

+1

All Articles