Access element of inner array
arrays, delphi
Solution
If I understand you correctly, you need to define a private function which will act as a "getter" for a default property:
NOTE: code untested
type
TIntClass = class
private
// returns a value from myInts based on Index parameter
function getItem(Index: Integer): Integer;
private
myInts : TList<Integer>;
...
public
property Items[Index: Integer]: Integer read getItem; default;
end;
...
implementation
function TIntClass.getItem(Index: Integer): Integer;
begin
Result := myInts[Index];
end;
so now you can do:
procedure test;
var
LMyIntClass: TIntClass;
L5thElemValue: Integer;
begin
L5thElemValue := LMyIntClass[4]; // first element is accessed using LMyIntClass[0]
end;
Problem
Given a class like this: ``` TIntClass = class private myInts : TList<Integer>; ... end; ``` how can I access an element of the inner list using the [] operator, e.g. ``` myIntList = TIntClass.Create(); myIntList[5]; ``` ? Thanks in advance.