Default array-property

Top  Previous  Next

What is translated > Properties > Default array-property


If a class has a default property, you can access that property in Delphi with the abbreviation object[index], which is equivalent to[index]. C# has an analogue indexer notation which Delphi2C# uses to translate default array-properties



  // Class with Indexed properties

  TRectangle = class


    fCoords: array[0..3] of Longint;

    function  GetCoord(Index: Integer): Longint;

    procedure SetCoord(Index: Integer; Value: Longint);


    property Coords[Index: Integer] : Longint

             read GetCoord write SetCoord; Default;





private class TRectangle : TObject


  private int[] fCoords = new int[4/*# range   0..  3*/];


  //# private int GetCoord(int Index);


  //# private void SetCoord(int Index, int Value);

  /*property Coords [Index: integer]: int read GetCoord write SetCoord default ;*/

  public int ReadPropertyCoords(int Index) { return GetCoord(Index);}

  public void WritePropertyCoords(int Index, int Value){SetCoord(Index, Value);}

  public int this[int Index]




      return GetCoord(Index);




      SetCoord(Index, value);




  public TRectangle() {}



In addition Delphi2C# creates the same ReadProperty and WriteProperty methods as for non default indexed properties. The existence of these additional methods makes it easier translate calls to indexed properties in a general way.

This page belongs to the Delphi2C# Documentation

Delphi2C# home  Content