浅谈Delphi2009控件移植

当Delphi支持了Unicode,它将会变成什么样子呢?
我的看法如下:
1. 开发变得复杂了,因为要更多的考虑编码问题
2. 绝大多数控件都需要修改,以使其能适应Delphi2009
3. 多国语言的软件得到了较好的支持

第一点和第二点,相信很多人都有体会了,原本在Delphi2007上通顺利编译通过的项目,放到Delphi2009上就要进行很大的改动。特别是API的调用,MessageBoxA改成MessageBoxW之类,会让原本简单的程序变得很复杂。
我在论坛上承接移植控件的项目时,已经有很深的体会。比如说 str: array[0..15] of Char,原本这个 str 是可以直接拿来用作PChar,但是现在就必须 PChar(string(str)),或许这有一点不方便,但是这对于Delphi2009来说,完全没有办法。因为它不可能放弃Ansi。

如果想不修改编码就在Delphi2009上编译Delphi2007的项目,可以使用 {$H+} 编译预处理,这将把字符串编码设为Ansi,而不是使用默认的Unicode。
当然了,这仅仅是针对一些简单的项目可以如此处理。对于复杂的控件,如DevExpress,RemObjects等等,用这一招完全无效,还是得老老实实的修改代码。由于编译器改动太大,使得一些原本能顺利使用的语法也需要重新考虑。类似于 Boolean(ArrStr[1]) := True; 这样的代码已经不被支持。

下面来说说修改控件的问题,主要是编码问题,已有一些总结如下:
1. 使用{$H+}来避免字符串解析为Unicode
2. 使用StrPCopy函数,来对Char数组赋值,ArrStr := str; 已经不再支持了
3. 使用PChar/PWideChar来生成字符串指针。
4. 对于Length(str)要特别小心,在Unicode的情况下,一个汉字的长度和一个英文字母的长度都是1,而Ansi情况下,一个汉字长度是2。
5. 数据相关的控件最麻烦,TDataSet被大幅修改,因此从TDataSet继承来的控件,大多数override的方法也需要同步修改
6. StrPas(@ArrStr[0])这种写法不被支持,应用Str: string; StrPas(PChar(Str)); 来代替
7. 转义在先不被支持,如上面说的Boolean(ArrStr[1]) := True; 这样的代码可修改为 ArrStr[1] := IfThen(True, #1, #0);
8. PropertyEditor中的字符串必须是Ansi的,不然会导致内存泄漏(不知正式版还有没有这个问题。。)
9. ISAPI 及一些特定的API没有W的形式,它们只允许使用Ansi,因此传入参数时,必须用PAnsiChar(AnsiString(Str))进行转换

一些新语法的问题,比如说HashMap,可以按Java的写法,修改成IMap<T,T>和THashMap<T,T>
诸如此类的不再多说,泛型的使用是必然的,也是必须的,当然这对于控件的相关修改会比较大,但是能使控件更完善。
另外,由于Delphi2009支持反射,以往用RTTI获取类成员的代码,如果为了精简,可以使用反射单元的相关成员来代替。不知有没有人测试过反射和RTTI的率,个人感觉,反射比RTTI慢一些,但是反射的功能远远强于RTTI。因此,开发时要用哪个,还是按照实际情况来决定比较好。

再来谈谈第三点,它对多国语言的支持强化了,我们可以在一个软件里,用上我们能够想像到的任何一种语言,而且都可以正确的显示(虽然对于我来说,完全用不到英文以外的语言,但是还是要说一下的)。但是这种多语支持却做得并不尽人意。本地化向导可以帮助完成一部分事情,但是自己要做的事还是很多。而TSiLang是第三方,并且收费的,虽然实现多语很方便,但是我相信会去购买的人也不多吧。
Delphi完全可以在多语方面再做得更好一些,还有个小小的bug,以色列文会乱码,不过中国的用户应该永远碰不到这问题了吧。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
一些老的件的集合: ------------------------------------------------------------------ xtoolbar.zip 41K 作者: Jean-Philippe Bernardy. 很不错的工具条件 armenutb.zip 33K 作者: Albert Research。 提供用TListView选择全部的 Menu Item的工具条件 dfssatausbar.zip 36K 作者: Brad Stowers。 TDFSStatusBar 是加强版 TStatusBar 构件,能够在其内放置其他构件(可在IDE环境瞎直接拖放),提供显示键盘上( CAPS Lock、NUM Lock、SCROLL Lock) 的状态,并提供进度显示进度及当前时间日期等多项功能 dfstoolbar.zip 10K 作者: Brad Stowers。 TDFSToolBar 是增强型的 TToolBar 构件,提供类似 Netscape Communicator 般的工具条,能够放到最大化及还原 sfoutbar.zip 23K 作者: Sylvain Frere. 类似Microsoft Outlook制条件,功能有支持大小图标显示,平滑滚动,快捷键,多重选择等 tbargood.zip 44K 作者: Seth Taylor。 配置 TForm TiTle的件,功能很多 colorbtn.zip 9K Windows95风格的选择颜色的按钮元件 bcolorbtn.zip 26K 作者: Brad Stowers. Windows95风格的选择颜色的按钮元件 explbtn.zip 37K 作者: Fabrice Deville 。 TExploreButton 是类似 Microsoft Internet Explorer 3.0 式样的 Speed Button gradbutt.zip 13K 作者: Harm TGradBtn 是能够显示渐变颜色的 TButton 构件,并能制按钮上文字以多种立体样式显示 avhebchk.zip 13K 作者: Alex Zanis. 在右边显示选择勾的CHeckBox件,适合从右到作的语言如阿拉伯语. amcbrb.zip 10K 作者: Alexander Meeder。 以BMP图片自定义显示外观的增强型 TRadioButton 及 TCheckBox 构件 noshape.zip 86K 作者: Michael Tran 能够照指定的BMP 图像外观直接变成按钮外观的增强型按钮构件,带Exe演示程序 hnoshape.zip 4K 能够照指定两个BMP 图像变成按钮外观的增强型按钮构件 btchkbox.zip 5K 增强型TCheckBox 构件,可以按不同的选取状态选择各自BMP图片 jcheck10.zip 12K 很漂亮的增强型TCheckBox 构件 lightchk.zip 2K 作者: Frederic Vanmol。 圆形 LED 类型的 TCheckBox 构件,可以加亮变暗. speedrol.zip 1K 可以根据Button不同状态(Up,Down,Over)显示不同图片,支持一个大Glyph分成三个按钮图. transrad.zip 2K 作者: Jason Looney. 透明Ridio Button torrybtn.zip 81K 作者: Maxim Peresada, Rob Schoenaker. TTorryButton 是增强型的 TSpeedButton 构件,外观如同一个普通的 TLabel 般,当鼠标移动至按钮上方,立即显示出按钮边框及加亮的LED 类型.带Exe演示程序 jcheck10.zip 12K 作者: Jan Hulala。 Windows98 外观的增强型 TCheckBox 构件. coolbtn.zip 2K 作者: Geert Vos。 TCoolButton2 是增强型的 TSpeedButton 构件,当鼠标移至其上方时按钮上的文字将会出现阴影 corelbtn.zip 2K 作者: Peter Theill。 提供类似 Corel 公司产品( Corel Photo Paint )中的特殊样式按钮 mscheckb.zip 5K 作者: Vasily Kholopov. 增强型的 TBitBtn 构件,当被鼠标按下时能够改变 Glyphs 格式 .BMP 的显示内容 shakebtn.zip 36K 作者: Harm. Sh
TsiLang® Components Suite includes a number of highly professional, easy-to-use VCL components, wizards and tools for building multi-language applications under Delphi and C++Builder. On the one hand, our product dramatically simplifies the entire process of globalization, and on the other hand it allows you to provide your customers with quality, user-friendly applications that can switch from one locale to another on-the-fly. We would like to describe some of the features of TsiLang Components Suite that make the product unique: Our suite enables you to localize everything that should be localized: string-type properties of components, "hard-coded" string constants, resource strings, system locale and standard dialog strings, as well as other properties that may affect the appearance of controls (for example, the size and position of labels may be changed for each language if required). You can choose where to store the translation data: either internally (this is ideal for lightweight applications – a single EXE file, no DLLs, databases, etc) or externally in special files (this approach allows you to change translations without recompiling the project, so even your end-user may update the translations at run-time). Such essential tools as TsiLang Expert and Resource Strings Wizard, which are included in the suite, help you to manage the translation process of you projects in a simple and convenient fashion. So, a large project might be prepared for globalization literally in a few minutes. The TsiLang Expert adds TsiLang components to the project's forms and data modules, adjusts their properties, and scans the project files for "hard-coded" strings. TheResource Strings Wizard allows you to extract and add to translation data the resource strings of your project even if they are hidden somewhere in a .dcu (.obj) file without the source code. A specialized tool shipped with the suite, the SIL Editor, can be freely redistributed and allows you to separate the tra
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值