Var

strUtf8: UTF8String; nChar: Integer; begi n strUtf8 := 'Some text '; nChar := 210;

strUtf8 := strUtf8 + UTF8String (AnsiChar (nChar)); nChar := 128;

strUtf8 := strUtf8 + UTF8String (AnsiChar (nChar));

Log ('String: ' + strUtf8); Log ('CodePage: " + IntToStr (

StringCodePage (strUtf8))); Log ( 'Address: " + IntToStr ( Integer (Pointer (strUtf8))));

DisplayStringData (strUtf8); DisplayRawData (strUtf8); end;

This time passing the string as an AnsiString performs an actual conversion (which is a lossy conversion, as the characters cannot be represented by a AnsiChar), while the RawByteString operations process the original string directly and produce the correct output:

UTF-8 string String: Some text C CodePage: 6500l Address: 28804892

Disp1ayStringData(str: AnsiString) String: Some text ? CodePage: 0 Address: 28804732

Disp1ayRawData(str: RawByteString) String: Some text C CodePage: 6500l Address: 28804892

In the program you can see more tests done with custom-defined string types. Like with the UTF8String test, each time you pass a custom string as an AnsiString a conversion takes place, which is potentially lossy, while using the RawByteString parameter you can keep the string in its original value and display it correctly. Here is a selection of the output lines:

Latin string String: Some text O

Disp1ayStringData(str: AnsiString) String: Some text O?

Disp1ayRawData(str: RawByteString) String: Some text O

Cyrillic string String: Some text T$>

Disp1ayStringData(str: AnsiString) String: Some text ??

Disp1ayRawData(str: RawByteString) String: Some text T$>

Was this article helpful?

0 0
Project Management Made Easy

Project Management Made Easy

What you need to know about… Project Management Made Easy! Project management consists of more than just a large building project and can encompass small projects as well. No matter what the size of your project, you need to have some sort of project management. How you manage your project has everything to do with its outcome.

Get My Free Ebook


Post a comment