Delphi Handbooks Collection


Delphi XE Handbook


Delphi 2010 Handbook


April 28, 2011

Getting Ready for Delphi 64

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.

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.





 

10 Comments

Getting Ready for Delphi 64 

Instead of waiting for 64bit I have already ported all 
of my DLL's (that needed to be in 64 bit) with Visual 
Studio.  And because I have done so, I personally now 
do not need Delphi 64 bit anymore (waiting for 6 years 
was too long).  So the question is a newer Delphi IDE 
and what it has to offer over D2007.  And to go from 
D2007 to XE2, I now have to port all my code to 
unicode.  I would not have a problem with that, except 
I have never seen a step by step set of instructions on 
what needs to be done with the code to make the 
transition.  The above example is very useful for 64 
bit.  What about a series of examples on how to migrate 
to unicode?
Comment by Brett Graffin [http://launchpadoffice.com] on April 28, 16:47

Getting Ready for Delphi 64 

Of my four major production Delphi projects, only
three could be successfully migrated to Delphi 2007,
and one had to stay on Delphi 7. I have tried to
migrate all them to Delphi 2009 and failed. I'm now
planning a major overhaul for that Delphi 7 project
that will hopefully bring it to Delphi 2007 with a
potential for a future migration to Unicode. But the
remaining three Delphi 2007 projects will likely stay
on 2007 forever. So despite being a big fan of Unicode
and a proponent of having all the freshest versions of
everything, I'm still dreaming of a full migration to
Delphi *2007*.
Comment by Alexander D. on April 28, 17:26

Getting Ready for Delphi 64 

 Actually, WParam does become come 64 bit. WinDef.h 
defines it like this:
typedef UINT_PTR WPARAM;
Comment by Giel on April 28, 17:51

Getting Ready for Delphi 64 

 Also lots of good tips at:
http://stackoverflow.com/questions/4051603/how-should-
i-prepare-my-32-bit-delphi-programs-for-an-eventual-
64-bit-compiler
and
http://stackoverflow.com/questions/1568685/how-to-
also-prepare-for-64-bits-when-migrating-to-delphi-
2010-and-unicode
Comment by Louis Kessler [http://www.beholdgenealogy.com] on April 28, 23:14

Getting Ready for Delphi 64 

 @Alexander: So what was the obstacle that made
migration to Unicode a showstopper for your projects?
Comment by Colin Johnsun on April 29, 03:00

Getting Ready for Delphi 64 

@Colin: The obstacles are third-party components the
projects are based on, that are unsupported because
the companies that made them are now out of business
(Dream Company components, AHM Triton Tools and
several others). They use strings a lot, and do it in
hacky ways, so that updating the components for
Unicode would be harder than migrating away from those
components.
Comment by Alexander D. on April 29, 08:39

Getting Ready for Delphi 64 

Brett Graffin posted above - What about a series of 
examples on how to migrate to unicode?

Get Cary Jensen's blog post, webinar replay and white 
paper:

http://caryjensen.blogspot.com/2010/01/migrating-
existing-delphi-applications.html

http://www.embarcadero.com/images/dm/technical-
papers/delphi-unicode-migration.pdf

http://forms.embarcadero.com/forms/AMUSCA1003UnicodeJens
enWebinarRecording
Comment by on April 29, 19:15

Getting Ready for Delphi 64 - unicode migration 

Brett Graffin posted above - What about a series of 
examples on how to migrate to unicode?

Get Cary Jensen's blog post, webinar replay and white 
paper:

http://caryjensen.blogspot.com/2010/01/migrating-
existing-delphi-applications.html

http://www.embarcadero.com/images/dm/technical-
papers/delphi-unicode-migration.pdf

http://forms.embarcadero.com/forms/AMUSCA1003UnicodeJens
enWebinarRecording
Comment by David I [http://blogs.embarcadero.com/davidi/] on April 29, 19:15

Getting Ready for Delphi 64 

It would be a great thing if Emb could give a small
update for Delphi 2007, the last ANSI Delphi version.
If they could make at least a datatype UnicodeString
that is equivalent to WideString and a NativeInt that
is NOT an Int64 but a Longword conform the 32 bit
platform it compiles to. This would make it much
easier for us to try to migrate the controls /
libraries from D2007 to XE and to Delphi 64bit
Comment by Ritsaert Hornstra on April 30, 14:12

Getting Ready for Delphi 64 

2 Brett: 6 years ago 64-bit was extremely rare. There 
was absolutely no sense of implementing x64 bit compiler 
until recent years. While waiting you might compile your 
DLLs with FreePascal instead of full rewriting them.

2 Ritsaert: you may easily implement this yourself. Good 
suggestion though. One tiny patch which fixes the 
NativeInt declaration enabling creating universal code.
Comment by feuer on May 28, 21:41


Post Your Comment

Click here for posting your feedback to this blog.

There are currently 0 pending (unapproved) messages.