Detect device orientation change Delphi Firemonkey
To detect device orientation change, you can use the following example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
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); |