Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there an easier way to convert Delphi 7 to Delphi 2009?

Is there an easier way to convert Delphi 7 to Delphi 2009? or is there a way to use a Delphi 7 unit in a Delphi 2009 project?

I have a unit in Delphi 7 but the behavior is all messed up when I try to use it in my Delphi 2009 project.

It has a lot of differences like:

 Hangul = 'ㄱㄲㄴㄷㄸㄹㅁㅂㅃㅅㅆㅇㅈㅉㅊㅋㅌㅍㅎ' +
           'ㅏㅐㅑㅒㅓㅔㅕㅖㅗㅛㅜㅠㅡㅣ';
 ShowMessage(Copy(Hangul, 1 + (I) * 2, 2));

Shows the characters one at a time in Delphi 7 but two at a time in Delphi 2009. So I needed to change it to:

ShowMessage(Copy(Hangul, 1 + I, 1));

but that was the easiest, it get's more confusing..and the algorithm isn't mine so I can't figure out the entirety of the program.

Any help would be appreciated.

EDIT: and if anybody is interested to see the code here is the LINK. It's the unit HanInput; part. It translates keys (in english) and outputs the Korean characters. And no, I don't understand Korean.

like image 372
Dian Avatar asked Jan 21 '23 17:01

Dian


2 Answers

I'd have a look at the encoding of your .pas file. You can do that using Notepad++ for example. If it is anything but UTF-8, change it to UTF-8 using notepad++. That should preserve the characters and make them readable for D2009. Oh and make sure the BOM (Byte Order Mark) for UTF-8 sis included.

Not sure whether the file will then still be usable in D7 though... (Don't know when UTF-8 support was added to the IDE).


The Hangul strings in your example and the HanInput unit from your link have two bytes per character. This tells me that they are intended to be UTF-16 encoded.

This is sort of confirmed by the MultiByteToWideChar calls, even though they are used on the arguments rather than the constants. If you are actually getting UTF-16 encoded into the functions, you could get rid of that call, but you still need to find a way to deal with the constants.

Dealing with the constants - I don't see all too many in that HanInput unit - could be as simple as copying the strings to a new Ansi encoded Notepad++ file, changing its encoding to UTF-8 and then copying the strings back to your unit. You may want to ensure that you first copy all strings to a new notepad++ file, then convert them and then copy them back, as the IDE editor will probably ask you whether you want to change the units format to UTF-8 and that may mangle the constants.

like image 180
Marjan Venema Avatar answered Mar 05 '23 03:03

Marjan Venema


In D7 Sizeof(Char) equals 1, while in D2009 it is 2. So this should help you:

ShowMessage(Copy(Hangul, 1 + (I) * Sizeof(Char), Sizeof(Char)));
like image 21
Uwe Raabe Avatar answered Mar 05 '23 03:03

Uwe Raabe