Indexed properties |
Top Previous Next |
What is translated > Properties > Indexed properties
Values which are specified by an index can be set or get by an indexed property. The index either can be a constant as in the example below or a variable as in the example following afterwards:
TRectangle = class private fCoords: array[0..3] of LongInt; function GetCoord(Index: Integer): LongInt; procedure SetCoord(Index: Integer; Value: LongInt); public Property Left : LongInt Index 0 read GetCoord write SetCoord; Property Top : LongInt Index 1 read GetCoord write SetCoord;
Property Right : LongInt Index 2 read GetCoord write SetCoord; Property Bottom : LongInt Index 3 read GetCoord write SetCoord; 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 Left = { index = 0, read = GetCoord, write = SetCoord }; __property int Top = { index = 1, read = GetCoord, write = SetCoord }; __property int Right = { index = 2, read = GetCoord, write = SetCoord }; __property int Bottom = { index = 3, read = GetCoord, write = SetCoord }; 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 Left : int read GetCoord write SetCoord;*/ int ReadPropertyLeft() { return GetCoord(0);} void WritePropertyLeft(int Value){SetCoord(0, Value);} /*property Top : int read GetCoord write SetCoord;*/ int ReadPropertyTop() { return GetCoord(1);} void WritePropertyTop(int Value){SetCoord(1, Value);} /*property Right : int read GetCoord write SetCoord;*/ int ReadPropertyRight() { return GetCoord(2);} void WritePropertyRight(int Value){SetCoord(2, Value);} /*property Bottom : int read GetCoord write SetCoord;*/ int ReadPropertyBottom() { return GetCoord(3);} void WritePropertyBottom(int Value){SetCoord(3, Value);} public: TRectangle() {} };
Again there is a simplified notation for C++Builder, while for other compilers only published Access methods can be created
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; 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 }; 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;*/ int ReadPropertyCoords(int Index) { return GetCoord(Index);} void WritePropertyCoords(int Index, int Value){SetCoord(Index, Value);} public: TRectangle() {} };
|
This page belongs to the Delphi2Cpp Documentation |
Delphi2Cpp home Content |