Shareware Beach

Wednesday, 15 August 2007

What You’re Missing if You’re Stuck with Delphi 7

Filed under: Software Development — Jan @ 8:13

My Delphi 2007 for Win32 post from last February has been attracting a lot of comments. Whaddayaknow! Searching for Delphi 2007 on Google lists that post as the 4th result.

The initial release of Delphi 2007 was a bit marred by new bugs in the Forms.pas unit. These were caused by code changes needed to support the Application.MainFormOnTaskBar property. If you set this to True before you call Application.Initialize, then your application will associate the main form’s Handle with the taskbar button rather than Application.Handle. This should do away with longstanding issues like Tile Horizontally leaving a gap the size of one phantom window, or your application appearing twice in certain Alt-Tab replacements.

Fortunately, Delphi 2007 update 1 is out already, and fixes the Forms.pas bugs. If you don’t make any change to your code, it’ll work the same when compiled with Delphi 2007 as with previous versions.

If you’re still using Delphi 7 or earlier, Delphi 2007 is a must have upgrade. You can buy the Delphi for Win32 personality separately if that’s all you need (unlike Delphi 2005 and 2006 which bundled all personalities). Don’t worry about the impending “Highlander” release. Highlander will have no new features on the Win32 side. Highlander updates the Delphi for .NET personality. If you buy the Highlander studio product (all personalities), you’ll get the same Delphi 2007 for Win32 and C++Builder 2007 that are already available separately, plus the new version of Delphi for .NET.

The main reason to upgrade is that the IDE now runs without issue on Vista. Though you may not use Vista as your primary development platform (I use XP), you definitely want to be testing all your products on Vista. And that’s much easier if you can debug right within the IDE.

CodeGear has published some articles on their site explaining important new features available in Delphi 2007, but not in Delphi 7. I’ll reiterate that all of this applies to good old Win32 development. The new IDE requires the .NET framework, but your applications definitely won’t.

Language and compiler features since Delphi 7

The most popular language feature is probably the new “” syntax. E.g. to iterate over all stings in a list, you can write “for S in MyList do Something(S);”. This is like the foreach operator in other languages, without introducing a new keyword.

Operator overloading allows you use any class in an expression using Delphi’s standard operators. E.g. if A, B and C are types of TMatrix, you could do matrix addition simply with C := A + B. All you need to do is to add one class function to the TMatrix type that takes two parameters and returns the result of the addition. You’ll use the new “operator” keyword instead of “function”, and give the method a predetermined name like “Add” for the + operator.

Class helpers were first introduced in Delphi 8 (the maligned .NET-only release). A class helper essentially allows you to add methods to an existing class, without creating a new class as descending from the original class would do. If the exising class has descendants, the helper methods will also be available in the descendants. E.g. if you create a class helper for TStrings, then all its descendants like TStringList and TComboBoxItems will also have the helper methods. This is a bit of a hack, actually. The only situation in which you should use this is when you really can’t modify the original class directly, e.g. because you don’t have the source code. That’s exactly the situation Borland faced with the classes provided by the .NET framework. No source for Borland to modify. Class helpers are now also available in the Win32 personality.

A lot of class design features from .NET were added to Delphi for .NET and now to Delphi for Win32 as well. These include “strict private” and “strict protected”, for design purists who believe that friends (classes in the same unit) shouldn’t touch each other’s private members. Classes can now be declared abstract in their entirity. Classes can be marked sealed, and methods marked final, preventing descendants and overridden methods. Classes can now contain class constants, class types (including nested classes), class variables and class properties. All of these apply to the class as a whole rather than each instance. In C# parlance these are “static” members.

New VCL features since Delphi 7

Starting with Delphi 2007, VCL applications are themed by default, so they look great on XP and Vista. The TForm.GlassFrame property now allows your forms to use the Vista Aero glassing effect.

New VCL components for new Vista features include TTaskDialog, TFileOpenDialog and TFileSaveDialog.

TFlowPanel and TGridPanel are two new VCL components for automatic layout management. The new Margin and Padding properties work like margin and padding in cascading style sheets (CSS) on the web when you set AlignWithMargins to True and use the Align property to align the control. If you’re tired of setting pixel positions and sizes on all your controls, these new components and properties will save your day.

The TCategoryButtons and TButtonGroup components allow you to easily implement a control like the new component palette in the IDE. And if you’re not using one of the heaps of freeware TTrayIcon components, Delphi finally includes one of its own.

New IDE features since Delphi 7

Actually, this should read: “totally new IDE since Delphi 7″. The first time you try the new IDE, it’ll come across as a big slow beast. But it’ll quickly grow on you when you discover all the new features. The article linked above has a bunch of screen shots.

Only two items in that article don’t have screen shots. This includes the “enhanced debugging features” item. This item alone is well worth the upgrade. E.g. the local variables view can now show local variables for any function on the call stack. All variable views, including local variables, watches, and even the tooltips can now show all fields in objects when you click the + to expand the object’s node. If some of those fields are objects, those can be expanded too. This is tremendously useful. Delphi 7 would only show a useless pointer address, requiring you to manually add watches to see individual object fields.

If you’re interested enough in Delphi 2007 to make it all the way to the bottom of this long article, you know you need it! Unless you always write bug-free code, those debugging features alone are well worth the few hundred dollars for the upgrade. Remember: you get the Delphi 2007 upgrade discount no matter which previous version you have, even if that’s Delphi 1.


  1. Does it let you create objects on the stack, when I tried D7 I was disappointed to find I could only create objects on the heap which makes cleaning up memory and resources more difficult than it should be.

    Comment by Tony Edgecombe — Wednesday, 15 August 2007 @ 16:00

  2. In Delphi, types declared as “class” are always a pointer to an object created on the heap. Types declared as “record”, on the other hand, are value types that are allocated simply by declaring a variable of that type. So if you have a record variable as a local variable in a procedure, it will be created on the stack.

    In Delphi 2007 (and I think 2006 too, but not in Delphi 7), record types can have member procedures and functions.

    Comment by Jan Goyvaerts — Thursday, 16 August 2007 @ 17:33

Sorry, the comment form is closed at this time.