[PATCH] Default array property overloads
Original Reporter info from Mantis: ryan_joseph @genericptr
-
Reporter name: Ryan Joseph
Original Reporter info from Mantis: ryan_joseph @genericptr
- Reporter name: Ryan Joseph
Description:
Patch to allow overloading of default array properties.
- All default properties must have the same name if within the same class (names can be different for subclasses). This is for backwards compatibility for classes that declare multiple defaults in different classes.
- Currently to allow overloading you must declare the property as default. Maybe this should be for all array properties?
- See tests for more examples.
type
TValue = TObject;
TList = record
function GetValueWithInt(index: integer): TValue;
function GetValueWithString(index: string): TValue;
function GetValueWithPair(index: integer; key: string): TValue;
property Values[index: integer]: TValue read GetValueWithInt; default;
property Values[index: string]: TValue read GetValueWithString; default;
property Values[index: integer; key: string]: TValue read GetValueWithPair; default;
end;
{ ... }
var
c: TList;
v: TValue;
begin
v := c[1];
v := c['key'];
v := c[1,'key'];
v := c.values[1];
v := c.values['a'];
v := c.values[1, 'a'];
end.
Additional information:
Full source at: https://github.com/genericptr/freepascal/tree/array_prop_overload
When the code is reviewed and confirmed I'll make a better patch. Just putting it in to the pipeline for now.
Mantis conversion info:
- Mantis ID: 35772
- Version: 3.3.1
- Monitored by: » imants_gulbis (Imants Gulbis)