Delphi 10.4.2 FMX 응용 프로그램 이벤트 TApplication Event 재론

Delphi 10.4.2 FMX 응용 프로그램 이벤트 TApplication Event 재론
 
 
바로 이전 테스트 코드를 보면 알 수 있습니다.
function TfmxMainUI.AppEvent(
  AAppEvent: TApplicationEvent; AContext: TObject): Boolean;
//:AContext             。             ,AContext null。
var
  LAppEventStatus :string;
begin
  Result := true;
  case AAppEvent of
    TApplicationEvent.FinishedLaunching:
      begin
        if FifMemo then Memo1.Lines.Add('  FinishedLaunching          :');
      end;
    TApplicationEvent.WillTerminate:
      begin
        if FifMemo then Memo1.Lines.Add('  WillTerminate                ');
      end;
    TApplicationEvent.EnteredBackground:
      begin
        //:  10.4 for Android10       :
        //:                  :
        //:     :     :=nil  
        //:(nil       TObject.disposeOf = FreeAndNil(TObject)  )
        //:FreeAndNil 10.4 10.3.3     
        //TimerGlobal.Enabled := false;
        //TimerGuangGao.Enabled := false;
        ///          UI     ,    :
          //if FifMemo then Memo1.Lines.Add('       ');
          //Text_0201.Text:=TInterlocked(FRestSearchFrequency).ToString;
        //EnteredBackground:                         ,
        //:             。
      end;
    TApplicationEvent.WillBecomeInactive:
      begin //:WillBecomeInactive:        :   :          EnteredBackground
        //TimerGlobal.Enabled := false;
        if (FDMem_CustomerAppID.Active=false) then LAppEventStatus:='  WillBecomeInactive:      '
        else LAppEventStatus:='  WillBecomeInactive:      ';
        if FifMemo then Memo1.Lines.Add('       :'+sLineBreak+LAppEventStatus);
        {if FifMemo then Memo1.Lines.Add(
          'App       (      )    :'+sLineBreak
          +'1、          :'+sLineBreak
          +string('').PadLeft(8,#32)+'          '+sLineBreak
          +string('').PadLeft(8,#32)+' UI        ,'+sLineBreak
          +string('').PadLeft(8,#32)+'          '+sLineBreak
          +string('').PadLeft(8,#32)+'     !');
        if FifMemo then Memo1.Lines.Add(
          '*  :        :'
          +string('').PadLeft(8,#32)+'      UI   '+sLineBreak
          +string('').PadLeft(8,#32)+'    、     '+sLineBreak
          +string('').PadLeft(8,#32)+'          '+sLineBreak
          +string('').PadLeft(8,#32)+'      !'+sLineBreak
          );}
      end;
    TApplicationEvent.WillBecomeForeground:
      begin
        if (FDMem_CustomerAppID.Active=false) then LAppEventStatus:='               :       '
        else LAppEventStatus:='               :     ';
        if FifMemo then Memo1.Lines.Add('2、  WillBecomeForeground     ,         :'+LAppEventStatus);
        //TimerGlobal.Enabled := true;
        //TimerGuangGao.Enabled := true;
      end;
    TApplicationEvent.BecameActive:
      begin //:BecameActive:       :  :
        //TimerGlobal.Enabled := true;
        if (FDMem_CustomerAppID.Active=false) then LAppEventStatus:='       :       '
        else LAppEventStatus:='       :     ';
        if FifMemo then Memo1.Lines.Add('3、  BecameActive       :'+LAppEventStatus);
      end;
    TApplicationEvent.TimeChange:
      begin
        if FifMemo then Memo1.Lines.Add('  TimeChange             :');
        //          。
        //  ,                  ,        。
      end;
    TApplicationEvent.LowMemory:
      begin
        if FifMemo then Memo1.Lines.Add('         LowMemory     :');
        //              。
        //               ,                 。
      end;
    TApplicationEvent.OpenURL:
      begin
        if FifMemo then Memo1.Lines.Add('iOS App     URL   :');
      end;
  end;

end;

원리:
//unit FMX.Platform;

  { Application events }

  TApplicationEvent = (FinishedLaunching, BecameActive, WillBecomeInactive, EnteredBackground, WillBecomeForeground, WillTerminate, LowMemory, TimeChange, OpenURL);

  TApplicationEventHelper = record helper for TApplicationEvent
  const
    aeFinishedLaunching = TApplicationEvent.FinishedLaunching deprecated 'Use TApplicationEvent.FinishedLaunching';
    aeBecameActive = TApplicationEvent.BecameActive deprecated 'Use TApplicationEvent.BecameActive';
    aeWillBecomeInactive = TApplicationEvent.WillBecomeInactive deprecated 'Use TApplicationEvent.WillBecomeInactive';
    aeEnteredBackground = TApplicationEvent.EnteredBackground deprecated 'Use TApplicationEvent.EnteredBackground';
    aeWillBecomeForeground = TApplicationEvent.WillBecomeForeground deprecated 'Use TApplicationEvent.WillBecomeForeground';
    aeWillTerminate = TApplicationEvent.WillTerminate deprecated 'Use TApplicationEvent.WillTerminate';
    aeLowMemory = TApplicationEvent.LowMemory deprecated 'Use TApplicationEvent.LowMemory';
    aeTimeChange = TApplicationEvent.TimeChange deprecated 'Use TApplicationEvent.TimeChange';
    aeOpenURL = TApplicationEvent.OpenURL deprecated 'Use TApplicationEvent.OpenURL';
  end;

  TApplicationEventData = record
    Event: TApplicationEvent;
    Context: TObject;
    constructor Create(const AEvent: TApplicationEvent; AContext: TObject);
  end;
  TApplicationEventMessage = class (System.Messaging.TMessage)
  public
    constructor Create(const AData: TApplicationEventData);
  end;

  TApplicationEventHandler = function (AAppEvent: TApplicationEvent; AContext: TObject): Boolean of object;

  IFMXApplicationEventService = interface(IInterface)
    ['{F3AAF11A-1678-4CC6-A5BF-721A24A676FD}']
    procedure SetApplicationEventHandler(AEventHandler: TApplicationEventHandler);
  end;

unit System.Messaging;

type

  /// Base class for all messages
  TMessageBase = class abstract;
  TMessage = TMessageBase;
  {$NODEFINE TMessage} // Avoid ambiguity with 'Winapi.Messages.TMessage'

  TMessage = class (TMessage)
  protected
    FValue: T;
  public
    constructor Create(const AValue: T);
    destructor Destroy; override;
    property Value: T read FValue;
  end;


 
 

좋은 웹페이지 즐겨찾기