Hi,
I have unit with Ansi strings but i want to compile it as UTF-8 how to ask the compiler to convert it to utf8 before compile it?
Thanks in advance

Mailing lists / fpc-pascal / 2010-09
8 messages · 4 people · –
Reply by email Subscribe to this list Your subscription
Read-only archive. Use j and k to move between messages.
Hi,
I have unit with Ansi strings but i want to compile it as UTF-8 how to ask the compiler to convert it to utf8 before compile it?
Thanks in advance
You can use {$codepage utf8} I think, but if you are using ISO8859-6 (Arabic right ?) then I'm not sure that it will convert it, but rater treat it as a UTF-8
Ido
I have unit with Ansi strings but i want to compile it as UTF-8 how to ask the compiler…
Zaher Dirkey wroteI have unit with Ansi strings but i want to compile it as UTF-8 how to ask the compiler to convert it to utf8 before compile it?
By saying that the unit has ansi strings do you mean that is has some types like:
X: ansistring;Or that the text of the unit itself is in an iso encoding?
For the second case probably using a editor which can convert between encodings like Notepad++ would solve the issue. You can use it to convert your unit to UTF-8.
I have unit with Ansi strings but i want to compile it as UTF-8 how to ask the compiler…
Zaher Dirkey wroteI have unit with Ansi strings but i want to compile it as UTF-8 how to ask the compiler to convert it to utf8 before compile it?
The compiler itself can only convert from utf-8 and several ISO code pages into utf-16 at compile time (i.e., change string constants into widestring constants). If you want to convert them to utf-8, you have to use a text editor as Felipe mentioned.
Jonas
Becuase i use this unit in Delphi 7 and Lazarus with my local language.
What for -Fm<x> parameters?
Thanks
You can use {$codepage utf8} I think, but if you are using ISO8859-6 (Arabic right ?)…
Yes it is Arabic in Windows Win1256, but {$codepage utf8} not worked, it is give me Malformed string.
Thanks
Becuase i use this unit in Delphi 7 and Lazarus with my local language. What for -Fm<x>…
Those tell the compiler that your source has been stored in that particular code page, and then the compiler will convert all string constants *from* the specified code page *to* widestring (which then at run time is converted back to the active ANSI code page; not to UTF-8).
If you want to do that, you have to wrap all your string constants with utf8encode(). That takes a widestring as parameter and returns an UTF-8 string. However, that is not Delphi-compatible either.
In the long term, native utf8string support will solve your problem, but right now what you want is not possible afaik.
Jonas
Yes it is Arabic in Windows Win1256, but {$codepage utf8} not worked, it is give me…
In the Virtual Magnifying Glass I used the following solution:
1> All my strings come from a translations manager
2> When they are updated (because the user selected a different language for example) then I also added the following code:
{$ifndef fpc}
<<-- here convert all utf-8 strings to ansi for Delphi usage
{$endif}And now it works fine.
procedure TTranslations.UpdateTranslations;