Implementing iOS Delegate In FireMonkey C++

  

Im following Brian Long’s video on accessing iOS API’s but trying to implement it in C++. Managed to get my head around it until he implemented a Delegate for UIAlertView. This is what I have so far:

#pragma region UIAlertView – Using Delegate
class TAlertViewDelegate : public TOCLocal, public UIAlertViewDelegate
{
//Virtual in .hpp I believe means that its going to be defined somewhere else
public:
void __cdecl alertView(_di_UIAlertView alertView, int clickedButtonAtIndex);
void __cdecl alertViewCancel(_di_UIAlertView alertView);
};
_di_UIAlertViewDelegate Delegate;
#pragma region Helper Function – Returns A ObjC Pointer To An NSString From A Unicode String
void * PNSSTR(const String str)
{
return ((_di_ILocalObject)StrToNSStr(str))->GetObjectID();
}
#pragma end_region

void __cdecl TAlertViewDelegate::alertView(_di_UIAlertView alertView, int clickedButtonAtIndex)
{
//Could Use Log::d again but will use NSlog
Iosapi::Foundation::NSLog(PNSSTR(“UIAlertView Button Pressed!”));
switch(clickedButtonAtIndex)
{
case 0:
Log::d(“You Clicked Cancel”);
break;
case 1:
Log::d(“You clicked Yes”);
break;
case 2:
Log::d(“You clicked No”);
break;
case 3:
Log::d(“You clicked Maybe”);
break;
}
alertView->setDelegate(nil);
Delegate = nil;
}

void __cdecl TAlertViewDelegate::alertViewCancel(_di_UIAlertView alertView)
{
Log::d(“Alert View Was Cancelled”);
alertView->setDelegate(nil);
Delegate = nil;
}
void __fastcall TForm1::ListBoxItem6Click(TObject *Sender)
{
_di_UIAlertView alertView;
Delegate = TAlertViewDelegate(); —-> COMPILER ERROR: See Below
alertView = TUIAlertView::Alloc();
__try
{
alertView = TUIAlertView::Wrap(alertView->initWithTitle(
StrToNSStr(“A Very Important Question”), //Title
StrToNSStr(“Do you like me? :)”), //Message
((_di_ILocalObject)Delegate)->GetObjectID(), //Delegate
StrToNSStr(“Cancel”), //Cancel Button Caption
nil //Other Button Caption
));
/*Add Some More Buttons….*/
alertView->addButtonWithTitle(StrToNSStr(“Absolutley!”));
alertView->addButtonWithTitle(StrToNSStr(“Nope.”));
alertView->addButtonWithTitle(StrToNSStr(“Meh :|”));
alertView->show();
}
__finally
{
alertView->release();
}
}
#pragma end_region

However I am not sure if I have created the delegate correctly – but I am getting a compiler error saying “allocating an object of abstract class type ‘TAlertViewDelegate’“. Looking at the source the TOCLocal has a constructor so therefor as I am subclassing it do I call TAlertViewDelegate::TOCLocal()?

Any help would be appreciated!

Attached below the UIAlertViewDelegate interface from iOSapi.UIKit.hpp:

__interface INTERFACE_UUID(“{A52A64A0-AA7E-422E-B7A4-8EFCF2C20A49}”) UIAlertViewDelegate : public Macapi::Objectivec::IObjectiveC
{
#ifndef __aarch64__
virtual void __cdecl alertView(_di_UIAlertView alertView, int clickedButtonAtIndex) = 0 /* overload */;
#else /* __aarch64__ */
virtual void __cdecl alertView(_di_UIAlertView alertView, long clickedButtonAtIndex) = 0 /* overload */;
#endif /* __aarch64__ */
virtual void __cdecl alertViewCancel(_di_UIAlertView alertView) = 0 ;
virtual void __cdecl didPresentAlertView(_di_UIAlertView alertView) = 0 ;
#ifndef __aarch64__
virtual void __cdecl alertViewDidDismissWithButtonIndex(_di_UIAlertView alertView, int didDismissWithButtonIndex) = 0 ;
#else /* __aarch64__ */
virtual void __cdecl alertViewDidDismissWithButtonIndex(_di_UIAlertView alertView, long didDismissWithButtonIndex) = 0 ;
#endif /* __aarch64__ */
};

Comments are closed.