Skip to content

‘Undocumented’ Win32 in Delphi 2005

Yesterday, I was surprised to find out that there are people who don’t know that Delphi 2005 also contains a Win32 personality. Not only does it contain such a personality, the compiler also has a few enhancements I would only have expected in the .NET version.

Class helpers

Class helpers were initially devised to help port Delphi’s Win32 RTL and VCL code to .NET. Using class helpers, Borland was able to map Delphi’s TObject to .NET’s System.Object, and some other Delphi base classes to their .NET equivalent as well, while retaining their Delphi- typical properties and methods. But it seems that class helpers are also available in the Win32 compiler. To me, it is not entirely clear how this could be exploited, but I’m sure that one day, someone will come up with some nifty solution to a problem, using class helpers.

If you want to know how class helpers work, there is a section on them in the online help for Delphi 2005.

Strict private and strict protected

The private and protected sections of Delphi classes were, according to purists, severely flawed, because they did not prevent access to private or protected fields or methods from code in the same unit. The Delphi RTL and VCL actually use this "friend" concept, so it was not so easy to simply remove it.

But in .NET, private and protected really had to be just that, i.e. no other code should have access to these items (except of course descendant classes to protected items). So we got strict private and strict protected sections. Although this is not documented, it seems that these are also available in the Win32 compiler (thanks to Rob Kennedy for finding out). I’m sure that those who have been asking for this for a long time will be pleased to hear this.

Dotted unit names

OK, this feature is not entirely new. Delphi 7 also had it, but it was not documented or enforced there. I specifically call them dotted names, and not namespaces, because AFAIK, the concept of namespaces is still reserved for .NET. Still, I think it makes it easier to name units.

Are there more of these?

If anyone knows more of these undocumented compiler enhancements (also for .NET), I’d love to hear about them, and I will include them in this or a new blog entry.

{ 4 } Comments

  1. Rossen Assenov | May 11, 2005 at 9:16 am | Permalink

    Nested type declarations are also available in Win32 :

    type

    TOuterClass = class

    strict private

    type

    TInnerClass = class

    end;

    public

    end;

  2. Gerrit Beuze | May 11, 2005 at 9:34 am | Permalink

    You might want to check these, but here’s a list from memory:

    #1 default array properties (indexers) can be overloaded (have the same name as long as the array parameter list is "different"

    #2 identifier escape char & is supported: you might have var &object: TObject;

    #3 static class methods supported

    #4 method directive "final" supported (check this!)

    #5 method directive "inline" supported (but not for .NET !)

    #6 "class" properties supported: class property InstanceCount: Integer read GetInstanceCount;

    #7 Compiler hint directive "experimental" supported

    #8 classes can contain "const" declarations

    #9 classes can contain "class var" declarations (static fields)

    #10 classes support the "abstract" and "sealed" directives

    Gerrit Beuze

    ModelMaker Tools

    http://www.modelmakertools.com

  3. Andrea Raimondi | May 25, 2005 at 7:01 am | Permalink

    I’m unsure if this applies only to D2005 or Delphi 7 too… anyway: you can overload constructors even without marking the parent constructor as "overload".

    It compiles, at least :-)

    Cheers,

    Andrew

  4. sebastien | August 18, 2005 at 6:40 am | Permalink

    <quote>

    To me, it is not entirely clear how this could be exploited, but I’m sure that one day, someone will come up with some nifty solution to a problem, using class helpers.

    </quote>

    Suppose you get a third party component not really well written, that does not do any kind of check of its arguments (sound familiar ?). And of course, you have not paid to get the source of this crappy peace of ****

    Now you was dressed up with Design By Contract in your earlies, so you take the pain to add some assertions _before_ calling the method of this component and maybe some assertions after returning from the method.

    I think you then get something like this (inspired from the sample given by Marco Cantu in Essential Delphi 8 for .NET) :

    Let’s the component doc says :

    TMyBuggyComponent :

    Text : string : blabla

    procedure DoSomething(arg: TObject) : blabla…

    You then could write :

    <code>

    uses MyBuggyComponent;

    type

    TMyBuggyComponentClassHelper = class Helper for TMyBuggyComponent

    public

    procedure DoSomething(const arg: string);

    end;

    procedure TMyBuggyComponentClassHelper.DoSomething(const arg: string);

    begin

    assert(arg <> ”);

    inherited DoSomething(arg);

    assert(Text <> ”);

    end;

    </code>

Post a Comment

Your email is never published nor shared. Required fields are marked *
Close