简体   繁体   English

如何在Delphi xe2中禁用unicode

[英]How to disable unicode in Delphi xe2

Is there a way to do this ? 有没有办法做到这一点 ?

I'm currently using 2007 and am looking to upgrade, but its very frustrating trying to get this new version to do anything. 我目前正在使用2007而且我正在寻求升级,但是试图让这个新版本做任何事情都非常令人沮丧。

The new behaviour of char, strings and Pchar in xe2 kills virtually every application and third party component I have tried on it. xe2中char,strings和Pchar的新行为几乎杀死了我尝试过的每个应用程序和第三方组件。

Is there a compiler option that gives D2007 compatibility. 是否有编译器选项可以提供D2007兼容性。 ?

There's no way to disable UNICODE in Delphi XE2 (or any version greater than 2009), however there are many resources that can help you to migrate your application: 在Delphi XE2(或任何大于2009的版本)中无法禁用UNICODE,但有许多资源可以帮助您迁移应用程序:

If there was a "Ansi switch" for Delphi 2009/2010/XE/XE2 (the unicode versions), you would simply be exchanging the problem you have now, with far worse problems. 如果Delphi 2009/2010 / XE / XE2(unicode版本)有一个“Ansi开关”,你只需交换现有的问题,就会出现更糟糕的问题。

For that reason, there can not be a switch. 因此,不能有转换。 This idea was discussed carefully, I happen to know from first-hand conversations with the people who made the decision, and the decision to break your code was not undertaken without due diligence. 这个想法得到了仔细的讨论,我碰巧从与做出决定的人的第一手对话中得知,并且没有尽职调查就没有决定打破你的代码。 There was simply no other way to go. 根本没有别的办法。 To make Delphi truly Unicode, it was essential to alias String=UnicodeString. 为了使Delphi成为真正的Unicode,别名String = UnicodeString是必不可少的。

Therefore, you must change all your String declarations to AnsiString , and Char to AnsiChar if you wish to have single-byte non-unicode character and string types in your application code. 因此,如果您希望在应用程序代码中使用单字节非unicode字符和字符串类型,则必须将所有String声明更改为AnsiString ,并将Char更改为AnsiChar In most of your code, and in most places, that is not necessary. 在大多数代码中,在大多数地方,这都不是必需的。 But where you explicitly need byte-size processing, such as binary protocols over RS232 and RS485, or binary file formats (EDA, etc), you need to change your code. 但是,如果您明确需要字节大小处理,例如RS232和RS485上的二进制协议,或二进制文件格式(EDA等),则需要更改代码。

If you don't want to port your code yourself, pay someone to do it. 如果您不想自己移植代码,请付费给某人。 I ported a huge library of scientific components and applications up myself, and it took me several weeks to test and find all the bugs. 我自己移植了一个庞大的科学组件和应用程序库,我花了几周的时间来测试并发现所有的错误。 Afterwards, I had a reasonable modern codebase that has not broken again since 2009 when I upgraded. 之后,我有了一个合理的现代代码库,自2009年升级以来没有再次破坏。

When you get to the XE/XE2 divide, you may encounter some more pain having to do with your code's assumptions that Pointer types are the same size as Integer or Cardinal, which is no longer true in Win64. 当你进入XE / XE2分界时,你可能会遇到一些更多的痛苦,这与你的代码假设指针类型与Integer或Cardinal的大小相同,这在Win64中已不再适用。 Again, Delphi guys have no desire to break your code, they're just following sane engineering practices, in that case, Win64 dictates certain things. 同样,德尔福人不想破坏你的代码,他们只是遵循理智的工程实践,在这种情况下,Win64决定某些事情。

Why didn't they change every VCL control property to USTRING instead of String? 为什么他们没有将每个VCL控件属性更改为USTRING而不是String? Why didn't they make every RTL function take both USTRING and STRING and provide overloads? 为什么他们不使每个RTL功能同时采用USTRING和STRING并提供过载?

Because normative Delphi development is now purely Unicode. 因为规范的Delphi开发现在纯粹是Unicode。 USTRING is, and would be a special case. USTRING是,并且将是一个特例。 String is the native (normative) string type, and it is, in fact, also known now as UnicodeString . String是本机(规范)字符串类型,实际上它现在也称为UnicodeString

It so happens you were already using a type alias. 碰巧你已经在使用类型别名了。 Strings in delphi 1.0 were limited to 255 characters in length. delphi 1.0中的字符串长度限制为255个字符。 When they introduced Delphi 2.0, and the long string type, internally called AnsiString , they aliased the existing common type String as String=AnsiString . 当他们引入Delphi 2.0和长字符串类型(内部称为AnsiString ,他们将现有的常见类型String别名为String=AnsiString When we got to Unicode, every VCL component and every VCL method that takes a string still takes a string. 当我们使用Unicode时,每个VCL组件和每个采用字符串的VCL方法仍然需要一个字符串。 However String is now String=UnicodeString . 但是String现在是String=UnicodeString

Delphi 7 already has WideString for example. 例如,Delphi 7已经有WideString We don't need a half-way move to unicode. 我们不需要中途移动到unicode。 Whether you realize it or not the entire software development world now expects string types to be unicode. 无论您是否意识到整个软件开发世界现在都希望字符串类型是unicode。 Delphi is part of a global phenomenon. 德尔福是全球现象的一部分。 The internet is unicode. 互联网是unicode。 Your Windows 7 operating system is pure native unicode. 您的Windows 7操作系统是纯本机unicode。

非正式的黑客 ,但它会带来更多的问题解决。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM