转至繁体中文版     | 网站首页 | 图文教程 | 资源下载 | 站长博客 | 图片素材 | 武汉seo | 武汉网站优化 | 
最新公告:     敏韬网|教学资源学习资料永久免费分享站!  [mintao  2008年9月2日]        
您现在的位置: 学习笔记 >> 图文教程 >> 软件开发 >> Delphi程序 >> 正文
升级到Delphi 6 - 兼容性问题之二         ★★★★

升级到Delphi 6 - 兼容性问题之二

作者:闵涛 文章来源:闵涛的学习笔记 点击数:1535 更新时间:2009/4/23 18:44:11
 

 

一.             潜在的二进制Form文件的不兼容

 

过去,新版本Delphi创建的二进制Form文件(或称DFM文件)可以被老版本的Delphi读取。但是现在不行了。某些二进制Form文件可能不能被老版本正确的读取,其原因是Delphi 6内部的字符串的流化和原先不同。过去,流化操作假设一个本地特殊的字符集。而现在新的流化操作假设字符集为UTF-8。由此带来的问题就是,如果Delphi 6的二进制Form文件中包含有码值大于127的字符出现(比如版权符®),则该文件就不能被Delphi 的老版本正确读取。

如果你想在老版本的Delphi 中打开Delphi 6 的Form文件,那么请先将该Form文件存为文本格式而非二进制格式。

 

Potential binary form file incompatibilities

In the past, binary form files (or DFM files) created with newer versions of Delphi could be read by older versions. This is no longer true in Delphi 6; some binary form files may be read incorrectly because of the way that Delphi 6 performs internal string streaming. In the past, streaming was performed assuming a locale specific character set. Now streaming assumes that the character set is UTF-8. As a consequence, if there are characters with a code greater than 127 (such as the copyright symbol ? in a Delphi 6 binary form file, that file cannot be read by older versions of Delphi.

If you intend to use a Delphi 6 form file (including older form files imported into and modified with Delphi 6) in an older version of Delphi, the file should be saved in text format instead of binary format.

 

二.             有关可赋值的常量

 

编译宏$WRITEABLECONST现在的缺省值改为关,这是为了防止Delphi的工程中运用可赋值的常量。可赋值的常量,也就是定义一个常量,但是却允许在运行期间改变其值。例子如下:

 

const

 

   foo: Integer = 12;

begin

   foo := 14;

end.

在以往的Delphi版本中,有这么一个特性:常量不是真正的常量。使用编译宏$WRITEABLECONST OFF,则以上的代码中的Begin和End之间的Foo的赋值将引发一个编译错误。若要避免它,只需将Foo的声明改为 var。

你可能有将常量用作一个可以初始化的局部变量的代码,比如:

 

procedure MyProc;

 

const

   somedata: Integer = 12;

begin

   Inc(somedata, 3);

end;

你要做的是将局部常量移到过程的外部声明,使其成为一个全局的变量。然后代码变为:

 

var

 

   somedata: Integer = 12;

procedure MyProc;

begin

   Inc(somedata, 3);

end;

对于过度依赖于常量的代码(比如ActiveX 控件的包装器),可以通过在源文件中插入一个{$WRITEABLECONST ON}的编译命令来修正。这一特性,在RTL, VCL, CLX,和 DB 等核心的源代码中被禁止使用,但是在周边的单元比如ActiveX 控件的包装器中倒可以接受。

总而言之,你应该意识到“可赋值的常量”这个说法的自相矛盾。Delphi的以往版本中的这一特性,只是为了与老的16位的编译器的兼容而保留,但现在对于Delphi的开发者来说已经毫无意义了。要养成好的编程习惯,尽量避免使用可赋值的常量。

 

Change in writeable constants

The $WRITEABLECONST compiler switch ( aka $J ) now has a default state of OFF, which will prevent Delphi projects from having writeable constants. Writeable constants refers to the use of a typed constant as a variable modifiable at runtime. Here is an example:

 

const

 

   foo: Integer = 12;

begin

   foo := 14;

end.

 

In prior releases of Delphi, this was an acceptable construct; constants weren''''t really constant. With $WRITEABLECONST OFF, this code will now produce a compile error on the assignment to the foo variable in the begin..end block. To fix it, simply change the const declaration to a var declaration.

You may have code that uses a typed const as an initialized local variable with global lifetime, like this:

 

procedure MyProc;

 

const

   somedata: Integer = 12;

begin

   Inc(somed

[1] [2]  下一页


[系统软件]BCB6 下devexpress 安装手记  [常用软件]Internet Explorer 6 Public Preview 最新出击!!
[常用软件]painter 6 手绘实例《油彩篇》  [常用软件]painter 6 手绘实例《粉彩篇》
[常用软件]Painter 6 手绘实例《胶彩篇》  [VB.NET程序]VB.NET实现DirectSound9 (6) 声音特效
[VB.NET程序]Visual Basic 6 逆向工程与反逆向工程 (2)  [VB.NET程序]Visual Basic 6 逆向工程与反逆向工程 (1)
[VB.NET程序]Vb 6 中的多态  [VB.NET程序]几个 WMI 的例子(初级) - 1
教程录入:mintao    责任编辑:mintao 
  • 上一篇教程:

  • 下一篇教程:
  • 【字体: 】【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
      注:本站部分文章源于互联网,版权归原作者所有!如有侵权,请原作者与本站联系,本站将立即删除! 本站文章除特别注明外均可转载,但需注明出处! [MinTao学以致用网]
      网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)

    同类栏目
    · C语言系列  · VB.NET程序
    · JAVA开发  · Delphi程序
    · 脚本语言
    更多内容
    热门推荐 更多内容
  • 没有教程
  • 赞助链接
    更多内容
    闵涛博文 更多关于武汉SEO的内容
    500 - 内部服务器错误。

    500 - 内部服务器错误。

    您查找的资源存在问题,因而无法显示。

    | 设为首页 |加入收藏 | 联系站长 | 友情链接 | 版权申明 | 广告服务
    MinTao学以致用网

    Copyright @ 2007-2012 敏韬网(敏而好学,文韬武略--MinTao.Net)(学习笔记) Inc All Rights Reserved.
    闵涛 投放广告、内容合作请Q我! E_mail:admin@mintao.net(欢迎提供学习资源)

    站长:MinTao ICP备案号:鄂ICP备11006601号-18

    闵涛站盟:医药大全-武穴网A打造BCD……
    咸宁网络警察报警平台