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?
private
function GetColumnValue(const ColumnName: string): string; overload;
function GetColumnValue(Index: Integer): string; overload;
procedure SetColumnValue(Index: integer; const Value: string);
public
property Values[const ColumnName: string]: string read GetColumnValue; default;
property Values[ColumnIndex: integer]: string read GetColumnValue write SetColumnValue; default;
end;
This means:
default
indexor propertiesValues
GetColumnValue
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With