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);