Delphi FMX检查应用程序状态更改


本文整理自网络,侵删。

 

当应用程序本身变为活动状态或进入后台时如何获取事件。使用IFMXApplicationEventService获取状态更改的通知。

uses

  FMX.Platform;

 

type

  TForm1 = class(TForm)

    Memo1: TMemo;

    procedure FormCreate(Sender: TObject);

  private

    { private 宣言 }

    /// <summary>

    ///  アプリケ?`ションの状?B?浠?イベントを受け取る?v数

    /// </summary>

    function AppEventHandle(AAppEvent: TApplicationEvent; AContext: TObject): Boolean;

  end;

 

procedure TForm1.FormCreate(Sender: TObject);

var

  service: IFMXApplicationEventService;

begin

  if TPlatformServices.Current.SupportsPlatformService(

      IFMXApplicationEventService, service) then

  begin

    service.SetApplicationEventHandler(AppEventHandle);

  end;

end;

 

function TForm1.AppEventHandle(AAppEvent: TApplicationEvent;

  AContext: TObject): Boolean;

begin

  Result := True;

 

  case AAppEvent of

    TApplicationEvent.FinishedLaunching: begin

      Memo1.Lines.Add('应用启动'); //delphitop.com

    end;

    TApplicationEvent.BecameActive: begin

      Memo1.Lines.Add('应用程序具有焦点');

    end;

    TApplicationEvent.WillBecomeInactive: begin

      Memo1.Lines.Add('焦点超出本申请的');

    end;

    TApplicationEvent.EnteredBackground: begin

      Memo1.Lines.Add('在后台运行的应用程序');

    end;

    TApplicationEvent.WillBecomeForeground: begin

      Memo1.Lines.Add('从背景返回');

    end;

    TApplicationEvent.WillTerminate: begin

      Memo1.Lines.Add('已经完成了应用');

    end;

    TApplicationEvent.LowMemory: begin

      Memo1.Lines.Add('缺少的设备的存储器');

    end;

    TApplicationEvent.TimeChange: begin

      // iOSのみ

      Memo1.Lines.Add('时间的重大变化');

    end;

    TApplicationEvent.OpenURL: begin

      // iOSのみ

      Memo1.Lines.Add('要求应用程序打开一个URL已接收');

    end;

  end;

end;

 

但是,我不确定AppEventHandle的返回值用于什么。.. ..

相关阅读 >>

Delphi 如何把一个exe做为res加入到dll中,并在运行时生成exe文件执行

Delphi xe3中如何crc验证函数?

Delphi api 函数: getcursorpos 与转换

Delphi firedac mysql 连接

Delphi获取操作系统安装磁盘盘符

Delphi 通过有道接口实现翻译

Delphi 禁用tedit右键菜单及复制粘贴

Delphi 如何遍历整个硬盘的各个目录,就像windows的查找功能那样

Delphi extractfileext() 获取文件后缀的函数

Delphi webservices传base64字串

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...