I have hit a problem in C++Builer XE3 that I have yet to find a good solution for. It involves the compability between pascal and c++, and overloaded constructors on the pascal side. C++ does not have named constructors; they are all given the name of the class.

I have hit a problem in C++Builer XE3 that I have yet to find a good solution for. It involves the compability between pascal and c++, and overloaded constructors on the pascal side. C++ does not have named constructors; they are all given the name of the class.

In XE3, the hpp generator has started pulling in constructors from my ancestor classes when it generates the list of constructurs to put in the hpp file. Unfortunately, this means that if you have a constructor with the same parameter list (but a different name) as an ancestor, the C++ compiler will complain about the duplicate.

The class in the example below is this single line declaration; it does not add anything to the base object.

  EnxThread = class(EnxBaseException);

Here's the hpp generated (somewhat abbreviated for clarity):

In XE2,

class PASCALIMPLEMENTATION EnxThread : public EnxBaseException
{
    typedef EnxBaseException inherited;
    
public:
    /* EnxBaseException.Destroy */ inline __fastcall virtual ~EnxThread(void) { }
    /* EnxBaseException.nxCreate / inline __fastcall EnxThread(unsigned aErrorCode)/ overload */ : EnxBaseException(aErrorCode) { }
    
public:
    /* Exception.Create */ inline __fastcall EnxThread(const System::UnicodeString Msg) : EnxBaseException(Msg) { }
...
};

In XE3, the same class comes out like this:

class PASCALIMPLEMENTATION EnxThread : public EnxBaseException
public:
    /* EnxBaseException.Destroy */ inline __fastcall virtual ~EnxThread(void) { }
    /* EnxBaseException.nxCreate / inline __fastcall EnxThread(unsigned aErrorCode)/ overload */ : EnxBaseException(aErrorCode) { }
    /* EnxBaseException.nxCreate / inline __fastcall EnxThread(unsigned aErrorCode, const System::UnicodeString aAltMsg)/ overload */ : EnxBaseException(aErrorCode, aAltMsg) { }
public:
    /* Exception.CreateRes / inline __fastcall EnxThread(NativeUInt Ident)/ overload */ : EnxBaseException(Ident) { }
    /* Exception.CreateResFmt / inline __fastcall EnxThread(NativeUInt Ident, System::TVarRec const *Args, const int Args_Size)/ overload */ : EnxBaseException(Ident, Args, Args_Size) { }
public
...
};


So far, I've investigated HPPEMIT'ing hand modified hpp code (will work, but it is an enormous task, given we have hundreds of units, most of which have multiple descendant exception classes)

Tried instead adding dummy parameter(s) to the constructors that would make the method signatures unique; now the compiler complains that it can't find these methods (bug?).


Any suggestion on what to do about this? Is the only way forward hand editing HPPEMITs?

Comments

  1. I've rarely, if ever, set my feet in C++Builder - so this is perhaps more a question for the C++Builder people than this Delphi crowd?

    ReplyDelete

Post a Comment