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的返回值用于什么。.. ..

相关阅读 >>

5种运行程序的方法具体应用实例

Delphi对cookie的操作

Delphi整理一(基础知识)

Delphi 简单的软件注册demo

Delphi获取系统字体列表

Delphi isleapyear、isinleapyear - 是否是闰年

Delphi 检查父进程

Delphi 判断文件是否正在被使用

Delphi 的内存操作函数(6): 跨进程的内存分配

Delphi通过idsmtp发送邮件的简单代码

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



打赏

取消

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

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

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

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

评论

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