Skip to content

Instantly share code, notes, and snippets.

@ccy
Created July 20, 2017 04:38
Show Gist options
  • Save ccy/82af31bcb6c376762ee92b196643d0e3 to your computer and use it in GitHub Desktop.
Save ccy/82af31bcb6c376762ee92b196643d0e3 to your computer and use it in GitHub Desktop.
FireMonkey: Detect device orientation change
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);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment