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 Object-Pascal with the abbreviation object[index], which is equivalent to object.property[index]. For C++Builder the translated code looks like:
type // Class with Indexed properties TRectangle = class private fCoords: array[0..3] of Longint; function GetCoord(Index: Integer): Longint; procedure SetCoord(Index: Integer; Value: Longint); public property Coords[Index: Integer] : Longint read GetCoord write SetCoord; Default; end;
->
C++Builder
class TRectangle : public TObject { typedef TObject inherited;
private: int fCoords[4/*# range 0..3*/]; int __fastcall GetCoord(int Index); void __fastcall SetCoord(int Index, int Value); public: __property int Coords[int Index] = { read = GetCoord, write = SetCoord/*# default */ }; public: __fastcall TRectangle() {} };
Other compilers
class TRectangle : public TObject { typedef TObject inherited;
private: int fCoords[4/*# range 0..3*/]; int GetCoord(int Index); void SetCoord(int Index, int Value); public: /*property Coords [Index: integer]: int read GetCoord write SetCoord default ;*/ int ReadPropertyCoords(int Index) { return GetCoord(Index);} void WritePropertyCoords(int Index, int Value){SetCoord(Index, Value);}int operator[ ](int Index) { return GetCoord(Index); } public: TRectangle() {} };
If there is an instance ot TRectangle the array can be accessed in Delphi simply by rect [i]. For C++Builder this becomes to:
rect->Coords[i]
and for other compilers:
rect->WritePropertyCoords(i, 0); ... = rect->ReadPropertyCoords(i);
|
This page belongs to the DelphiXE2Cpp11 Documentation |
DelphiXE2Cpp11 home Content |