简体   繁体   English

抓锁屏幕事件

[英]Catch Lock Screen Event

Good day. 美好的一天。 I am writing in C ++ Builder in Embarcadero Xe8. 我正在用Embarcadero Xe8中的C ++ Builder编写。 I do mobile application project on Ios and android and faced such problem: I can not catch the phone lock screen event. 我在Ios和android上进行移动应用程序项目,并遇到了以下问题:我无法捕获手机锁屏事件。 I used to always do so: 我以前总是这样做:

    bool TForm1::HandleApp(TApplicationEvent a, TObject *x)
{
    if (a == TApplicationEvent::EnteredBackground)
    {
        MediaPlayer1->Stop();
    }
    return true;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
  _di_IFMXApplicationEventService a;
   if (TPlatformServices::Current->SupportsPlatformService(__uuidof(IFMXApplicationEventService), &a))
   {
    a->SetApplicationEventHandler(TForm1::HandleApp);
   }
}

But an error: 但是有一个错误:

\\Unit1.cpp(33): cannot initialize a parameter of type 'TApplicationEventHandler' (aka 'bool ( closure *)(Fmx::Platform::TApplicationEvent, System::TObject __borland_class *__strong) __attribute ((pcs("aapcs-vfp")))') with an lvalue of type 'bool (__closure *)(Fmx::Platform::TApplicationEvent, System::TObject __borland_class *__strong)' FMX.Platform.hpp(252): passing argument to parameter 'AEventHandler' here \\ Unit1.cpp(33):无法初始化类型为'TApplicationEventHandler'的参数(又名'bool( 闭包*)(Fmx :: Platform :: TApplicationEvent,System :: TObject __borland_class * __ strong),__ attribute ((pcs(“ aapcs- vfp“))''),左值类型为'bool(__closure *)(Fmx :: Platform :: TApplicationEvent,System :: TObject __borland_class * __ strong)'FMX.Platform.hpp(252):将参数传递给参数' AEventHandler”在这里

I Do not know what else to try to do! 我不知道该怎么办! Could you please help me? 请你帮助我好吗?

Your HandleApp() method is missing the __fastcall calling convention: 您的HandleApp()方法缺少__fastcall调用约定:

bool __fastcall  TForm1::HandleApp(TApplicationEvent a, TObject *x)

Also, your call to SetApplicationEventHandler() needs to be like this instead: 另外,您对SetApplicationEventHandler()调用需要像这样:

a->SetApplicationEventHandler(&HandleApp);

This is important because the event handler is a __closure , so it carries two pointers inside of it - a pointer to the class method to call, and a pointer to the object instance that the method is called on (the this value of the method). 这很重要,因为事件处理程序是__closure ,因此它内部包含两个指针-指向要调用的类方法的指针,以及指向要调用该方法的对象实例的指针(方法的this值)。 。 When you pass the handler by class name only, the compiler doesn't know which object instance to act on, and thus cannot populate the __closure . 当仅通过类名称传递处理程序时,编译器不知道要对哪个对象实例进行操作,因此无法填充__closure The syntax above allows the compiler to see that HandleApp should be associated with the Form1 object. 上面的语法允许编译器看到HandleApp应该与Form1对象关联。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM