Array Properties read SubClass



Array Properties SubClass
Pas2JS pascal source code
type TSub = class Field: Integer; procedure Proc; procedure SetProp(v: string); property Prop: string write SetProp; end; type TTest = class function GetSub(x: Integer): TSub; property Sub[x: Integer]: TSub read GetSub; default; end; procedure TSub.Proc; begin Writeln('Sub ' + IntToStr(Field)); end; procedure TSub.SetProp(v: string); begin Writeln('SetProp ' + IntToStr(Field) + ': ' + v); end; function TTest.GetSub(x: Integer): TSub; begin Result := TSub.Create; Result.Field := x; end; { TApplication } procedure TApplication.RunApp; var t := TTest.Create; Begin (t).Sub[0].Proc; (t.Sub[1]).Proc; t.Sub[2].Proc; (t).Sub[0].Prop := 'a'; (t.Sub[1]).Prop := 'b'; t.Sub[2].Prop := 'c'; (t).GetSub(10).Proc; (t.GetSub(11)).Proc; t.GetSub(12).Proc; (t).GetSub(10).Prop := 'a'; (t.GetSub(11)).Prop := 'b'; t.Sub[12].Prop := 'c'; { CONSOLE OUTPUT SetProp 0: a SetProp 1: b SetProp 2: c SetProp 10: a SetProp 11: b SetProp 12: c }