Question

We have an application in delphi 2007 which writes contents of memo to a text file and loads it back. TMemo charset is set to AnisCharSet and Enable runtime themes in project options --> application is turned off. The content that is loaded is something like this "möglich" which contains umlaut characters. This application works fine in delphi 2007 which writes to text file and reads it back and show the content correctly. While writing to file memo converts the umlaut string to like this "mцchten" and when memo loads it back it correctly displays it.

Now we have the upgraded the same application to delphi xe2 and in here when the memo loads the text from file it doesn't display it properly i.e. instead of displaying umlaut string as "möglich", it displays "mцchten", the conversion which was happening in delphi 2007 doesn't seem occur when displaying umlaut characters in delphi xe2.

Can some one suggest what can be done to display umlaut characters properly in delphi xe2 application as well. It's just memo's savetofile and loadfromfile options are used without any encoding. In Xe2 enable runtime themes is turned off and memo's font charset is still Ansi.

The problem here is loading and showing the characters from the text file in delphi xe2 application which was saved using delphi 2007 application

Was it helpful?

Solution

Umlauts are codepage-sensitive in Ansi environments, like D2007, and thus require extra handling in Unicode environments, like XE2. As such, it is best to read/write your data using a codepage-neutral format instead, like UTF-8. Especially if the data has to move from one PC to another, where the OS default Ansi codepage may be different.

In this particular situation, you may have to find out what specific codepage was being used by the OS when the D2007 code saved the data (since it would have used the OS default Ansi codepage), and then explicitally tell the XE2 code to use that same codepage when reading the data. In XE2, the TStrings.LoadFrom...() methods have an optional TEncoding parameter You can use the TEncoding.GetEncoding() method to get a TEncoding object for a specific codepage.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top