Several years ago, I wrote a program for the local children's library so that they could keep track of all their books and see who had borrowed what. This is a classic database program, and like all of my programs, it was written with Delphi 7. Until recently, the library had an old PC which was running Windows XP, so there were no problems with my program (in terms of displaying Hebrew characters correctly).
A few months ago, their computer crashed and burned. Recently, the lady who runs the library (and who is also a neighbour of mine) got in touch: someone had donated an old laptop computer to the library, and she wanted me to get the program running on this new computer. Some of the data had been saved, some lost; she was prepared to compromise on this issue. When she showed me the laptop, it turned out that it was far from an old computer - it was running Windows 10!
I knew from experience that my programs would display as gibberish under this operating system, as it uses Unicode, whereas my programs are non-Unicode. In the past, I converted one of my programs to a unicode version, using the TNT components, so I wasn't too worried about this conversion ... until I started work on it.
The program which I had converted uses labels and edit boxes, but it doesn't use menus or data grids, which is what was required for the library program. After a great deal of faffing around yesterday, I discovered how I could implement menus and grids in the program - all the time, I was copying the program to my own laptop (running Windows 8.1) in order to see what had been converted successfully and what not.
I was having great difficulty with the data grids: they were showing gibberish despite the fact that they were TNT components. A database manager installed on my laptop displayed the Hebrew perfectly so I knew that the problem was not with the database. After a great deal of looking around on the Internet, I found one suggestion which seemed a little strange: set the computer's locale to display Hebrew (the question was about Hebrew, as it happens).
I copied the code (two lines) into my program, compiled it then tried it out on my laptop. It sort of worked: at first, the menu displayed in Hebrew and from right to left, but after I opened one of the forms which I had converted then closed it, I noticed that the menu had reverted to gibberish. Encouraged by this, I added the locale code at the form creation event and at its closing. On the laptop, the data grid displayed gibberish the first time it was displayed, but the second time, it displayed Hebrew! I then discovered that even forms which I had not converted displayed in Hebrew!!
So I added a little code which displayed this form before immediately destroying it. This should mean that everything would now display in Hebrew ... and it does! Just to make sure, I copied the program onto the target computer, and it worked perfectly the first time. I still have to hook up the menu to the various forms, but for all intents and purposes, the program has already been ported to display Hebrew on Windows 10 - seemingly without the TNT components.
Here is the magic code which seems to make the difference
SetThreadLocale ($040D); GetFormatSettings;
No comments:
Post a Comment