'How to implement indexed [] default property
I have a class which holds multiple filenames inside a TStringList. I can access a particular filename by index using:
myclass.stringlistclass[index]
But how can I get an filename using the following syntax?
myclass[index]
Is there a property I can implement to achieve this functionality?
Solution 1:[1]
Use "default" keyword on the indexed property. There can be one default property per class.
You can have multiple default properties per class, however these default properties must have the same name.
An example:
property Item[const Coordinate: TPoint]: TSlice read GetSlice write SetSlice; default;
property Item[x,y: integer]: TSlice read GetSlice write SetSlice; default;
You can even have the getters and setters share the same name, as long as they have the overload directive.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Johan |
