[fpc-pascal] FPC 3.x for Windows and code page conversion

Michael Van Canneyt michael at freepascal.org
Mon Nov 23 18:08:48 CET 2015

On Mon, 23 Nov 2015, Lubos Pintes wrote:

> Hello,
> Thanks for replies, I will try to explain this in other way:
> My system code page is windows-1250. When a string is sent to a COM 
> component, it is somehow converted to UTF-16. Thus FPC knows how to do 
> the conversion. Now I know that I am receiving text in UTF-8. Thus I 
> called UTF8ToANSI to uselessly convert the UTF-8 to ANSI and then FPC 
> converted it to UTF-16 to make COM happy.

Do not convert to Ansi. 
You should use unicodestring or widestring variables, and send that to COM.

> Although it worked well in many cases, a data loss may occur.
> So to reformulate this question, how to avoid this useless conversion 
> step? I thought that setting the default code page to UTF-8 just do the 
> trick.

COM only works with UTF16. The best way is to declare all strings that you 
intend to send to COM to Widestring or UnicodeString.


More information about the fpc-pascal mailing list