Utf8decode in delphi 7

I need to use delphi 7 to convert strings from utf8 to widestring. Can someone tell me why the following code does not work in delphi 7? The Utf8Decode function parameter is just a sample.

var ws: WideString; begin ws := Utf8Decode('[أمبير] خطأ تيار- تيار Ů…ŘŞŮاصل مطلق'); end; 

In delphi 7 this gives me a lot of question marks, however in bds2006 it works well.

Do I need to switch some compiler directive or how can I convert utf8String to Widestring in delphi 7?

Decision

There is nothing wrong with the Utf8Decode function. The result of evaluating the Delphi Code Insight Tooltip expression is misleading to me that it cannot display Widestrings. see image below:

Tooltip expression evaluation

but MessageBoxW can display text:

enter image description here

+4
source share
1 answer

I believe the problem is that Delphi 7 can only use ANSI for source files. Later versions of Delphi will use UTF-8 for source files, and in fact you can specify which encoding you want to use for your source files.

If you interpret the UTF-8 encoded string as ANSI (for example, using Notepad ++), you can paste the UTF-8 encoded literal into the ANSI source file. For example, this code creates a window with text using Delphi 6.

 ws := UTF8Decode('[ŘÅمبير] خط؊تيار- تيار Ů…ŘŞŮاصل مطلق'); MessageBoxW(0, PWideChar(ws), PWideChar(WideString(FloatToStr(CompilerVersion))), 0); 

enter image description here

Trying to look at your string literals like this is simply impractical. You probably need to start investing in resources.

+5
source

Source: https://habr.com/ru/post/1395229/


All Articles