property index



property_index
Smart pascal source code
type TTest = class function GetProp(i: Integer): String; procedure SetProp(i: Integer; v: String); property Items[i: Integer]: String read GetProp write SetProp; default; property Item1: String index 1 read GetProp write SetProp; property Item2: String index 2 read GetProp write SetProp; end; function TTest.GetProp(i: Integer): String; begin Result := 'Get ' + IntToStr(i); end; procedure TTest.SetProp(i: Integer; v: String); begin WriteLn('Set ' + IntToStr(i) + ' with ' + v); end; var o := TTest.Create; WriteLn(o[1]); WriteLn(o[2]); o[1] := 'hello'; o[2] := 'world'; WriteLn(o.Item1); WriteLn(o.Item2); o.Item1 := 'bye bye'; o.Item2 := 'test script'; {<<< RESULT - CONSOLE LOG >>> ----------------------------- Get 1 Get 2 Set 1 with hello Set 2 with world Get 1 Get 2 Set 1 with bye bye Set 2 with test script ----------------------------- {<<<<<<<<< THE END >>>>>>>>>}