Over the last few weeks, Embarcadero has started to publicly unveil a significant amount of information on the coming 64-bit Delphi compiler. Here I don't want to list the expected features of that compiler, but only suggest a few coding styles you can start to implement today, to get ready for porting of your code to 64 bit in the future.

Overall, the key difference will be that while all pointer types (pointers, object references, string references, dynamic array references, and so on) will change from 32 bit to 64 bit, some of the native numeric types (most notably, Integer) will remain 32 bit. So while in the past you could cast Integers to pointers, this won't work when compiling for a 64 bit target.

So here is the beginning of a compilation I plan extending in the future. I have tested this code on Delphi XE, using the 32 bit compiler. I think it will work, but certainly don't know for sure, since I haven't tried it in a 64 bit compiler. My guess is just as good as your guess!

1. Integer to NativeInt

Every time in your code there is a cast of a pointer or object reference to the Integer type, replace it with a cast to NativeInt. For example the following code saves the reference to an object in the Tag property (which according to Allen Bauer has been changed to NativeInt).

// classic code
Button1.Tag := Integer (Label1);

// portable code
Button1.Tag := NativeInt (Label1);


LParam is also a type

In a very similar way, pointers passed in Windows messages change their size. Actually, Windows messages change their size, with the wParam (originally a 16-bit word, later a 32-bit long) remaining 32 bit and the lParam (always 32-bit) extending to 64 bit. Although you can use the same NativeInt type, it is considered safer to cast pointer values for Windows messages using the LParam data type. This guarantees the maximum compatibility for any future (and past) version of Windows.

So for passing an object pointer within an application you can change your code as follows:

// classic code
PostMessage (Handle, WM_APP, 0, Integer (Button2));

// portable code
PostMessage (Handle, WM_APP, 0, LParam (Button2));

Avoid the Double Somersault

That's all for this first blog post on 64 bit migration. More will come. The best way to get ready for 64-bit Delphi is to migrate to Delphi XE, particularly if you still haven't moved at least to Delphi 2009. You certainly don't want to migrate to Unicode and 64-bit all at once, doing a double somersault which could break your back! The 64 bit migration seems to be easier than the Unicode migration, but could still be far from trivial if you have a lot of code. And there will be other issues: again, this is only a starting point for a series of blog posts.