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.
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
TMyRecordHelper = record helper for TMyRecord
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."