## CSDN博客

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

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.

procedure MyProc;

const

somedata: Integer = 12;

begin

Inc(somedata, 3);

end;

var

somedata: Integer = 12;

procedure MyProc;

begin

Inc(somedata, 3);

end;

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(somedata, 3);

end;

You will need to move the local const out of the procedure and declare it for what it is: a global variable. After making this change, the code segment above becomes:

var

somedata: Integer = 12;

procedure MyProc;

begin

Inc(somedata, 3);

end;

Code that relies heavily on the typed const quirk (such as the ActiveX control wrapper generator) can insert a {\$WRITEABLECONST ON} directive in the source file as a quick fix. This practice is forbidden in the RTL, VCL, CLX, and DB source code and discouraged in the IDE sources, but acceptable for fringe units such as ActiveX control wrappers.

In general, you should note that the phrase "writeable constant" is an oxymoron. Prior versions of Delphi allowed them by default to maintain compatibility with an older 16-bit compiler, which is no longer important for most Delphi developers. Use good programming practice; avoid writeable constants.

var

c: Cardinal;

i: Int64;

begin

c := 4294967294;

i := -c;

WriteLn(i);

end;

Unary negation of Cardinal type

In the past, Delphi handled unary negation of Cardinal type numbers using 32 bit operations, which could lead to some odd results. Here is an example of code which uses unary negation:

var

c: Cardinal;

i: Int64;

begin

c := 4294967294;

i := -c;

WriteLn(i);

end;

In previous versions of Delphi, the value of i displayed would be 2. This is obviously incorrect behavior for this case. In Delphi 6, the unary negation is handled after promoting the Cardinal type to a 64 bit signed type, so the final value of i displayed is -4294967294.

It is possible that existing code may rely on the incorrect behavior of unary negation. Delphi users should be aware of this new behavior. It may be worth your time to check your code for instances of unary negation of Cardinal variables, and make sure that your application responds to the new behavior appropriately.

任何引用了IDesigner的运行期Package，需要用IdesignerHook来防止运行期时需要designide。运动期代码中，IDesignerHook 足以应付。设计时间的代码也可以使用IDesigner，但是代码要象下例一样：

var

RealDesigner: IDesigner;

...

SomeDesignerHook.QueryInterface(IDesigner,RealDesigner);

...

IDesignerHook 的一个实例上获得真正的IDesigner接口。IDesignerHook的使用只需要引用ClassesForms两个单元。IDesigner还需要用DesignIntf，该单元被包含在许多其它Packatge中，而其中的一些可能导致不可再次分发。

Borland在此希望感谢Field的测试员Matt Palcic，感谢他让我们对此引起注意。

DsgnIntf renamed and related changes

References to DsgnIntf in your project should be changed to the new Delphi 6 name, DesignIntf. You may also need to add DesignEditors, VCLEditors and RTLConsts to your uses clause. You will also need to add designide to your package's requires list. References to dsnide50 should probably also be changed to designide if that isn't changed automatically by Delphi.

Any runtime packages that use IDesigner need to use IDesignerHook to avoid a requirement of designide at runtime. In runtime code, IDesignerHook should suffice. Design-time code can use IDesigner, but should use something like

var

RealDesigner: IDesigner;

...

SomeDesignerHook.QueryInterface(IDesigner,RealDesigner);

...

To get the real IDesigner interface from an instance of IDesignerHook. IDesignerHook only requires Classes and Forms to be available. IDesigner requires DesignIntf, which includes many other packages, some of which may not be redistributable.

Borland wishes to thank field tester Matt Palcic for bringing these changes to our attention.

Delphi 6中，类TComponentEditor有了不同的祖先。在Delphi 5中，它从TInterfacedObject

Component editor changes

The class TComponentEditor has a different ancestry in Delphi 6. In Delphi 5, it descended from TInterfacedObject; it now descends from a new class, TBaseComponentEditor. Also, the class TComponentEditorClass is now a class of TBaseComponentEditor instead of TComponentEditor. These changes in hierarchy may require you to modify your older Delphi projects.

Borland wishes to thank field tester Clive Walden for bringing these changes to our attention.

0 0