Array property

Top  Previous  Next

What is translated > Properties > Array property

 

As arrays cannot be returned by functions in C++ in contrast to Delphi, arrays may not be properties in C++ in contrast to Delphi. If there is such a property in Delphi it will be converted to according getter or setter functions in C++. The following code uses the same array TObjectArray and the same function CreateArray which are defined for the  previous example for returned arrays. 

 

 

TArrayClass = class

private

  FArray : TObjectArray;

public

 

  property Arr : TObjectArray read FArray write FArray;

end;  

 

->

 

class TArrayClass : public TObject

{

  typedef TObject inherited;

private:

  TObjectArray FArray;

public:

  /*property arr : TObjectArray read FArray write FArray;*/

  TObjectArray& ReadPropertyarr(TObjectArray& result) const {ArrAssign<3>(result, FArray); return result;}

  void WritePropertyarr(TObjectArray& Value){ArrAssign<3>(FArray, Value);}

};

 

 

ArrAssign is the common name of some template functions, which assign arrays to each other. The template parameter <3> specifies, that the arrays have three elements in one dimension.

 

In the following Test3 function the array of the class is initialized by means of the CreateArray function:

 

procedure Test3;

var

  C : TArrayClass;

begin

  C := TArrayClass.Create;

  C.arr := CreateArray;

end;

 

In the C++ translation an additional TObjectArray is needed,wich is passed to the CreateArray funtion at first. There  the elements of the array are initialized. Finally the array is is returned from CreateArray and becomes the array parameter of the writer function of the property.

 

 

void Test3()

{

  TArrayClass* C = NULL;

  C = new TArrayClass();

  TObjectArray arrayproperty__0; C->WritePropertyarr(CreateArray(arrayproperty__0, uniquetype()));

}

 

 

 

 

 

 



This page belongs to the Delphi2Cpp Documentation

Delphi2Cpp home  Content