This post continues from a question at C++ Builder Journal Forum with the help of Remy Lebeau. My problem is a lack of understanding about the Delphi RTTI and how to use it in C++ Builder. There is a lot of documentation of how to use the RTTI to get type information etc but not so much how to use it for discovery.
From my understanding the below should setup the methods within for RTTI discovery:
class DELPHICLASS MyClass : public MyOtherClass
{
public:
//Methods…
__published:
//Methods…
}
This is my class at the moment which overrides the virtual methods in the interface UIAlertViewDelegate in the Embarcadero iOS API iOSapi.UIKit.hpp.
class DELPHICLASS TAlertViewDelegate : public TOCLocal, public UIAlertViewDelegate
{
typedef Macapi::Objectivec::TOCLocal inherited;
INTFOBJECT_IMPL_IUNKNOWN(TOCLocal);
public:
virtual void __cdecl alertView(_di_UIAlertView alertView, aarch_int_t clickedButtonAtIndex);
virtual void __cdecl alertViewCancel(_di_UIAlertView alertView);
virtual void __cdecl didPresentAlertView(_di_UIAlertView alertView);
virtual void __cdecl alertViewDidDismissWithButtonIndex(_di_UIAlertView alertView, aarch_int_t didDismissWithButtonIndex);
};
However when I create an instance of this class and allocate it on the heap using:
_di_UIAlertViewDelegate Delegate = (UIAlertViewDelegate *)new TAlertViewDelegate();
I am getting a Delphi related RTTI error:
First chance exception at $00158015. Exception class EObjectiveC with message ‘RTTI for type UIAlertViewDelegate was not found. Perhaps missing {$M+}?’. Process Delegates (250202)
Changing my class methods from public to __published get rid of this error but cause an Access Violation, but looking at the call stack what is happening is:
TOCLocal Constructor Called
TRttiType GetMethods Called
Read Method Data
Read Extended Method Data
Read Object
Read Object Pointer
Read Object (again)
Create TRTTIInstanceMethodClassic
Access Violation
Clearly there is something wrong here with the RTTI as it is crashing after it is trying to get Method information? Could anyone with experience possibly help here?