Via Cà Matta 2 - Peschiera Borromeo (MI)
+39 02 00704272
info@synaptica.info

Detect device orientation change Delphi Firemonkey

Digital solution partner

Detect device orientation change Delphi Firemonkey

To detect device orientation change, you can use the following example:

uses System.Messaging, FMX.Platform;

var FId: Integer;

// Subscribe to TOrientationChangedMessage
FId := TMessageManager.DefaultManager.SubscribeToMessage(TOrientationChangedMessage, DoOrientationChanged);

// Write orientation change handler:
procedure TMyForm.DoOrientationChanged(const Sender: TObject; const M: TMessage);
var s: IFMXScreenService;
begin
  if TPlatformServices.Current.SupportsPlatformService(IFMXScreenService, s) then begin
    case s.GetScreenOrientation of
      TScreenOrientation.Portrait: ;
      TScreenOrientation.Landscape: ;
      TScreenOrientation.InvertedPortrait: ;
      TScreenOrientation.InvertedLandscape: ;
    end;
  end;
end;

// Unsubscribe the TOrientationChangedMessage
TMessageManager.DefaultManager.Unsubscribe(TOrientationChangedMessage, FId);