[Android]SetApplicationEventHandler

This is the forum for miscellaneous technical/programming questions.

Moderator: 2ffat

[Android]SetApplicationEventHandler

Postby Lena » Sun Dec 04, 2016 6:24 am

Hi!
I try use this deiphi code: http://delphifmandroid.blogspot.com/201 ... droid.html
Code: Select all
public:      // User declarations
     bool __fastcall HandleAppEvent(TApplicationEvent *AAppEvent, TObject *AContext);

//***


void __fastcall TForm1::FormCreate(TObject *Sender)
{
  IFMXApplicationEventService *aFMXApplicationEventService;
  if (TPlatformServices::Current->SupportsPlatformService(__uuidof(IFMXApplicationEventService), _di_IInterface(aFMXApplicationEventService)))
   aFMXApplicationEventService->SetApplicationEventHandler(HandleAppEvent);//<- ettor

}



[bccaarm Error] UnitMikros.cpp(330): cannot initialize a parameter of type 'TApplicationEventHandler' (aka 'bool (__closure *)(Fmx::Platform::TApplicationEvent, __borland_class *System::TObject __strong) __attribute__((pcs("aapcs-vfp")))') with an lvalue of type 'bool (__closure *)(Fmx::Platform::TApplicationEvent *, __borland_class *System::TObject __strong) __attribute__((pcs("aapcs-vfp")))'
FMX.Platform.hpp(256): passing argument to parameter 'AEventHandler' here

How fix?
Lena
BCBJ Master
BCBJ Master
 
Posts: 456
Joined: Sun Feb 06, 2011 1:28 pm

Re: [Android]SetApplicationEventHandler

Postby Lena » Sun Dec 04, 2016 7:10 am

Seem to be so
Code: Select all
public:      // User declarations
     bool __fastcall HandleAppEvent(TApplicationEvent AAppEvent, TObject *AContext);


//---------------------------------------------------------------------------
#include <stdlib.h>


 bool __fastcall TForm1::HandleAppEvent(TApplicationEvent AAppEvent, TObject *AContext)
{
   if (AAppEvent == TApplicationEvent::EnteredBackground)
    {
    //Close();
    //Application->Terminate();
     _exit(0);
    }
    return true;
}

//---------------------------------------------------------------------------

void __fastcall TForm1::FormCreate(TObject *Sender)
{

   _di_IFMXApplicationEventService Intf;
   if (TPlatformServices::Current->SupportsPlatformService(__uuidof(IFMXApplicationEventService)) )
   {
      Intf = TPlatformServices::Current->GetPlatformService(__uuidof(IFMXApplicationEventService));
      Intf->SetApplicationEventHandler(HandleAppEvent);
   }
}

Lena
BCBJ Master
BCBJ Master
 
Posts: 456
Joined: Sun Feb 06, 2011 1:28 pm

Re: [Android]SetApplicationEventHandler

Postby rlebeau » Mon Dec 05, 2016 3:18 pm

Lena wrote:Seem to be so


Yes, the signature of your HandleAppEvent() method was wrong. Here is the documented signature:

FMX.Platform.TApplicationEventHandler

In any case, your OnCreate event handler (you really should be using the Form class constructor instead) can be simplified to the following so you are not performing the same lookup twice:

Code: Select all
void __fastcall TForm1::FormCreate(TObject *Sender)
{
    _di_IInterface Intf;
    if (TPlatformServices::Current->SupportsPlatformService(__uuidof(IFMXApplicationEventService), Intf) )
    {
        _di_IFMXApplicationEventService EventService = Intf;
        EventService->SetApplicationEventHandler(HandleAppEvent);
    }
}
Remy Lebeau (TeamB)
Lebeau Software
User avatar
rlebeau
BCBJ Author
BCBJ Author
 
Posts: 1402
Joined: Wed Jun 01, 2005 3:21 am
Location: California, USA

Re: [Android]SetApplicationEventHandler

Postby Lena » Tue Dec 06, 2016 6:03 am

Thank You very much!
Lena
BCBJ Master
BCBJ Master
 
Posts: 456
Joined: Sun Feb 06, 2011 1:28 pm


Return to Technical

Who is online

Users browsing this forum: No registered users and 7 guests