What a good time to continue this series just after the major Delphi for .NET 2.0 launch, CodeGear RAD Studio 2007!
The previous post covered the exotic topic of Record Helpers. Today we'll look at another exotic-ish topic - overloaded default array properties.
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.
"Overloaded default array properties
A class or component can have an array property that is declared as default. This mechanism has now been extended to allow multiple overloaded default array properties - as long as the number or types of indexer parameters are different.
TMyObject = class
property Items[Index: integer]: string read GetItems write SetItems; default;
property Items[const Name: string]: string read GetNamedItems write SetNamedItems; default;
This means that you can use the array indexing syntax on the object instance - effectively overloading the array subscript operator .
MyObject := TMyObject.Create;
MyObject := 'The Answer';
MyObject['Bar'] := 'Yes';