There is no counterpart to class/record helpers in C++. However it is possible to translate Delphi code using class helpers to C++. This is demonstrated at the following example:

TStringsHelper = class Helper for TBase
  function GetTheObject(const AString: String): TObject; 
  procedure SetTheObject(const AString: String; const Value: TObject); 
  property ObjectFor[const AString : String]: TObject Read GetTheObject Write SetTheObject; 

becomes with DelphiXE2Cpp11 for C++Builder to

class TStringsHelper
  TStringsHelper(TBase* xpClass) : m_pClass(xpClass) {}
  TObject* __fastcall GetTheObject(const String& AString);
  void __fastcall SetTheObject(String& AString, TObject* Value);
  __property TObject* ObjectFor[const String& AString] = { read = GetTheObject, write = SetTheObject };
  TBase* m_pClass;

Of course, for other compilers than C++Builder the properties become setter and getter functions. If S is an instance of TBase, an assignment of a TObject like:

S.ObjectFor['a'] := Object;

becomes to:

TStringsHelper(s).ObjectFor[L"a"] = Object;

The trick is, that functions calls of the helper class are redirected to calls of the helped class inside of a local instance of the helper class. For example the setter method of TStringHelper might look like:

void __fastcall TStringsHelper::SetTheObject(String& AString, TObject* Value)
  int idx = 0;
  idx = m_pClass->IndexOf(AString);
  if(idx >- 1)
    m_pClass->Objects[idx] = Value;

   deutsch Deutsch

Latest News
DelphiXE2Cpp11 nifty class references offer [more...]

Delphi2C# beta offer [more...]