paxScript Demo. Arrays and Indexed Properties.


paxBasic

Class AClass

   Dim fZ = [10, 20, 30, 40, 50]
   
   Sub New()
   End Sub
   
   Default Property Z(I As Integer) As Integer
     Get
       return fZ(I)
     End Get
     Set
       fZ(I) = Value
     End Set
   End Property
   
End Class

Dim X = new AClass()
X(1) = 90
print X

paxC

class MyClass {
  var
    fZ = [10, 20, 30, 40, 50];
  
  function MyClass(){}
 
  property this[I] {
    get { return fZ[I]; }
    set { fZ[I] = Value; }
  }
}

var X = new MyClass();
X[1] = 90;
print x;

paxPascal

program Demo;
type
  TMyClass = class(TObject)
     fZ = [10, 20, 30, 40, 50];
     function GetZ(I: Integer): Integer;
     begin
       result := fZ[I];
     end;
     procedure SetZ(I, Value: Integer);
     begin
       fZ[I] := Value;
     end;
     property Z[I: Integer]: Integer read GetZ write SetZ; default;
  end;
  
  TMyArray = array[1..Random(10) + 2] of Integer;

var
  X: TMyClass;
  A: TMyArray;
begin
  X := TMyClass.Create;
  X[1] := 90;
  print X;
  print A;
end.


Copyright © 1999-2006 VIRT Laboratory. All rights reserved.