使用Delphi 7进行开发时,要为Delphi 2009及更高版本做好准备吗? [英] Get ready for Delphi 2009 and up when developing with Delphi 7?

查看:126
本文介绍了使用Delphi 7进行开发时,要为Delphi 2009及更高版本做好准备吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Delphi 7中开发Word插件,但是很快,我就会将其升级到Delphi 2010,正如您所知,因为2009版Delphi引入了新的字符串类型 UnicodeString ,它等于关键字字符串。另一方面,根据此线程,我们需要使用WideString与COM通信。

I'm developing a Word addin in Delphi 7, but soon I'll upgrade it to Delphi 2010, as you know, since version 2009 Delphi introduces the new string type UnicodeString which equals to the keyword string . On the other hand, according to this thread we need to use WideString to communicate with COM.

我的问题是,在当前在Delphi 7中进行开发时,为了将来为Delphi 2010做准备,我应该怎么做?当前,在我的代码中,我使用用户定义的类型UnicodeString,其思想是,当用D7编译时,我的字符串是WideString,当用D2009编译时,它是UnicodeString,我看到Virtual TreeView使用了这种技术,例如以下代码:

My question is, what should I do in order to get ready for Delphi 2010 in the future while currently developing in Delphi 7? Currently in my code I use a user-defined type UnicodeString, the idea is that when compile with D7 my string is WideString, when compile with D2009 and up it's UnicodeString, I see Virtual TreeView uses such technique ,like the following code:

{$ifndef COMPILER_12_UP}
type
  UnicodeString = WideString;
  PByte = PAnsiChar;
{$endif COMPILER_12_UP}


推荐答案

步骤1

通常,您应尽量使用正常类型:即String和Char

这样,您的代码将自动

注意:有一些特定于应用程序的例外。

Step 1
Usually you should stick to using the 'normal' types as far as possible: i.e. String and Char
This way your code will be 'automatically' converted when you upgrade.
NOTE : There are a few application-specific exceptions.

如果不这样做这样做,您可能会遇到升级在某些地方使用AnsiString的代码库时遇到的问题。当AnsiString = String时,在旧的Delphi中这不是问题。但是显然,当类型不再相同时,这是有问题的。

If you don't do this, you're likely to experience a problem I had when upgrading a library of code that had in some places used AnsiString. This wasn't a problem in old Delphi when AnsiString = String. But obviously this was problematic when the types were no longer the same.

第2步

阅读提供的准则迁移到Unicode Delphi2009。它提到使用字符串时通常会滥用的功能,因为假定每个字符都是1个字节。记下这些,并根据那些建议进行编码。

Step 2
Read the guidelines provided for migrating to Unicode Delphi 2009. It mentions the functions that are typically abused when working with strings because it is assumed that each character is 1 byte. Take note of these, and code according to those recommendations.

第3、4和5步

避免使用有条件的编译。

Steps 3, 4 and 5
Avoid the use of conditional compilation. You'll only give yourself more headaches.

步骤6、7、8、9和10

Don不要试图通过重新定义其内部类型来猜测编译器。您让自己感到头疼。关键是VCL,运行时库和第三方组件都对 String 是一个理解。升级到Delphi 2009时,仍将共享新理解。

Steps 6, 7, 8, , 9 and 10
Don't try to second guess the compiler by redefining its internal types. You're exposing yourself to many headaches. The thing is that the VCL, run-time libraries and 3rd party components all have an 'understanding' of what String is. The 'new understanding' will still be shared when you upgrade to Delphi 2009.

如果更改了该定义,则由于隐式兼容性,某些内容仍可以在旧版本中使用。 ;但是在Delphi 2009中突然发生变化时,它可能会崩溃。

If you change that definition, then things may still work in the old version due to implicit compatibility; however it is likely to break horribly when in Delphi 2009 things suddenly change.

记住!使用的字符串类型是Windows API调用的重要考虑因素。 Windows通常支持大多数功能的Ansi和Wide版本。在较早的Delphi中,默认使用Ansi版本。从Delphi 2009开始,默认使用Wide版本。

Remember! The kind of string used is an important consideration with Windows API calls. Windows typically supports both Ansi and Wide versions of most functions. In older Delp Ansi versions are used by default; and from Delphi 2009, Wide versions are used by default.

注释

关于COM开发中对WideString的关注:

较早版本的Delphi在String和WideString之间提供自动类型转换-让您的编译器在可能的情况下为您工作。显然,您的COM接口必须使用WideString进行声明,但是请避免使用其他任何东西。

Notes
Regarding your concerns about WideString in COM development:
Older versions of Delphi provide automatic typecasting between String and WideString - let your compiler work for you where it can. Obviously your COM interfaces have to be declared with WideString, but try to avoid anything beyond that.

EDIT

看看休斯提供的链接:使用Delphi 7开发时是否为Delphi 2009及更高版本做好了准备?

还要强调一下:每个新版本的Delphi都会尝试维护某种程度的向后兼容性(包括Delphi 2009)。 如果您只是正常编码,则不会受到很大程度的影响。实际上,反之亦然。 花哨的时间越多,遇到问题的可能性就越大。

Also just to emphasise: Each new version of Delphi attempts to maintain some level of backward compatibility (Delphi 2009 included). If you just code 'normally' you're unlikely to be impacted to any great degree. In fact the converse is generally true; the more fancy you get, the more likely you are to encounter problems.

我在转向新产品时遇到的唯一严重问题Delphi的版本为:

The only serious problems I've ever had with moving to new versions of Delphi are:


  • 没有源代码的第三方代码/库。

  • 未维护的第三方

  • Delphi 3中的Midas代码是一个特别艰巨的升级。 (但同样,绕过推荐技术的开发人员也是罪魁祸首。)

这篇关于使用Delphi 7进行开发时,要为Delphi 2009及更高版本做好准备吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆