簡體   English   中英

抓鎖屏幕事件

[英]Catch Lock Screen Event

美好的一天。 我正在用Embarcadero Xe8中的C ++ Builder編寫。 我在Ios和android上進行移動應用程序項目,並遇到了以下問題:我無法捕獲手機鎖屏事件。 我以前總是這樣做:

    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);
   }
}

但是有一個錯誤:

\\ 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”在這里

我不知道該怎么辦! 請你幫助我好嗎?

您的HandleApp()方法缺少__fastcall調用約定:

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

另外,您對SetApplicationEventHandler()調用需要像這樣:

a->SetApplicationEventHandler(&HandleApp);

這很重要,因為事件處理程序是__closure ,因此它內部包含兩個指針-指向要調用的類方法的指針,以及指向要調用該方法的對象實例的指針(方法的this值)。 。 當僅通過類名稱傳遞處理程序時,編譯器不知道要對哪個對象實例進行操作,因此無法填充__closure 上面的語法允許編譯器看到HandleApp應該與Form1對象關聯。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM