有没有更简单的方法将 Delphi 7 转换为 Delphi 2009?
有没有更简单的方法将 Delphi 7 转换为 Delphi 2009? 或者有没有办法在 Delphi 2009 项目中使用 Delphi 7 单元?
我在 Delphi 7 中有一个单元,但是当我尝试在 Delphi 2009 项目中使用它时,行为完全混乱。
它有很多差异,例如:
Hangul = 'ㄱㄲㄴㄷㄸㄹㅁㅂㅃㅅㅆㅇㅈㅉㅊㅋㅌㅍㅎ' +
'ㅏㅐㅑㅒㅓㅔㅕㅖㅗㅛㅜㅠㅡㅣ';
ShowMessage(Copy(Hangul, 1 + (I) * 2, 2));
在 Delphi 7 中一次显示一个字符,但在 Delphi 2009 中一次显示两个字符。 所以我需要将其更改为:
ShowMessage(Copy(Hangul, 1 + I, 1));
但这是最简单的,它变得更令人困惑..并且该算法不是我的,所以我无法弄清楚整个程序。
任何帮助将不胜感激。
编辑: 如果有人有兴趣查看这里的代码,请点击LINK。这是 unit HanInput;
部分。它翻译按键(英语)并输出韩语字符。不,我听不懂韩语。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我会看看你的 .pas 文件的编码。例如,您可以使用 Notepad++ 来完成此操作。如果不是 UTF-8,请使用 notepad++ 将其更改为 UTF-8。这应该会保留这些字符并使它们对于 D2009 来说是可读的。哦,请确保包含 UTF-8 sis 的 BOM(字节顺序标记)。
但不确定该文件是否仍可在 D7 中使用...(不知道 IDE 何时添加了 UTF-8 支持)。
您的示例中的 Hangul 字符串和链接中的 HanInput 单元每个字符有两个字节。这告诉我它们应该是 UTF-16 编码的。
MultiByteToWideChar 调用证实了这一点,即使它们用于参数而不是常量。如果您实际上将 UTF-16 编码到函数中,则可以摆脱该调用,但您仍然需要找到一种方法来处理常量。
处理常量 - 我在 HanInput 单元中没有看到太多 - 可以像将字符串复制到新的 Ansi 编码的 Notepad++ 文件一样简单,将其编码更改为 UTF-8,然后将字符串复制回您的单元。您可能需要确保首先将所有字符串复制到新的 notepad++ 文件,然后转换它们,然后将它们复制回来,因为 IDE 编辑器可能会询问您是否要将单位格式更改为 UTF-8,这可能会损坏常数。
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.
在 D7 中 Sizeof(Char) 等于 1,而在 D2009 中为 2。所以这应该对您有帮助:
In D7 Sizeof(Char) equals 1, while in D2009 it is 2. So this should help you: