Wednesday, May 30, 2007

DN4DP#12: Record Helpers

This post continues the series of The Delphi Language Chapter teasers from Jon Shemitz’ .NET 2.0 for Delphi Programmers book. The previous post explained how destructors and Free works in .NET. This one covers record helpers.

Note that I do not get any royalties from the book and I highly recommend that you get your own copy – for instance at Amazon.

"Record Helpers

Just as you can have class helpers to inject methods for a specific class (and its descendants) you can now also declare record helpers for a specific record type (or any value type defined in a .NET assembly). The syntax and capability is basically the same as for class helpers, but with class replaced with record.

TMyRecord = record
Field: string;
procedure Foo;

TMyRecordHelper = record helper for TMyRecord
procedure Bar;

Note: The record helper feature is mostly undocumented in Delphi 2006. It is currently used in the Borland.Delphi.System unit to inject methods into the System types Decimal, DateTime and Double that would otherwise not be available on the Compact Framework platform."

1 comment:

Kioskay said...

Hi Hallvard, that's one thing I'm particularly interested of. I mean, whether records are much more lightweight than classes/TObject. I've been preferring C++ structs over classes is many cases where I need code size and speed. I wonder if I should think the same about Delphi records. I'd like to hear more about that, any resources, links or more articles would be appreciated.

Copyright © 2004-2007 by Hallvard Vassbotn