Open array var parameters

Top  Previous  Next

What is translated > Types > Arrays > Array parameters > Open array var parameters

 

A special case of open array parameters is the use as var-parameter as for example at the CopyTo-method of TStringHelper:

 

procedure TStringHelper.CopyTo(SourceIndex: Integer; var Destination: array of Char; DestinationIndex, Count: Integer);

begin

  Move(PChar(PChar(Self)+SourceIndex)^, Destination[DestinationIndex], Count * SizeOf(Char));

end;

 

For this case d2c_openarray.h defines a special OpenArrayRef-type which can be used to pass dynamic arrays and strings to such methods.OpenArrayRef has a similar interface as a std::vector.

 

       template <class T>

       class OpenArrayRef

       {

       public:

               OpenArrayRef(std::vector<T>& v);

               OpenArrayRef(DynamicArray<T>& arr);  // C++Builder only

               OpenArrayRef(std::basic_string<T>& s);

               

               ...

 

       };

 

 

 

By use of this helper class the code above is converted to:

 

 

void TStringHelper::CopyTo(int sourceIndex, OpenArrayRef<Char> Destination, int DestinationIndex, int Count)

{

  Move(ustr2pwchar(m_Helped) + sourceIndex, Destination.data() + DestinationIndex, Count * sizeof(Char));

}

 

 

There are an additional OpenArrayRef2-type and an OpenArrayRef3-type derived form OpenArrayRef by which normal fixed arrays respectively ShortString's can be passed to such parameters..

 

 



This page belongs to the DelphiXE2Cpp11 Documentation

DelphiXE2Cpp11 home  Content