Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prevent screen rotation with android development in delphi xe5 Firemonkey

Tags:

android

delphi

I have found the following code to prevent the screen from rotating but when i compile i get a bunch of undeclared identifiers: IFMXScreenService, TPlatformServices. Obviously this is because of missing units. But i cannot find what unit it is.

Code:

procedure TLogin.FormCreate(Sender: TObject);
var
  ScreenService: IFMXScreenService;
  OrientSet: TScreenOrientations;
begin
  if TPlatformServices.Current.SupportsPlatformService(IFMXScreenService) then
  begin
    ScreenService := TPlatformServices.Current.GetPlatformService
      (IFMXScreenService) as IFMXScreenService;
    OrientSet := [TScreenOrientation.soLandscape];
    ScreenService.SetScreenOrientation(OrientSet);
  end;
end;

Any assistance would be great thank you.

Update:

The unit missing was FMX.Platform. But when i try to compile now, i get an error: \\android\\debug\\libproject.so: open: permission denied

like image 693
Marcel Avatar asked Oct 21 '25 18:10

Marcel


2 Answers

Add FMX.Platform to your uses clause, and get rid of the redundant call to GetPlatformService():

uses
  ..., FMX.Platform;

procedure TLogin.FormCreate(Sender: TObject);
var
  ScreenService: IFMXScreenService;
  OrientSet: TScreenOrientations;
begin
  if TPlatformServices.Current.SupportsPlatformService(IFMXScreenService, IInterface(ScreenService)) then
  begin
    OrientSet := [TScreenOrientation.soLandscape];
    ScreenService.SetScreenOrientation(OrientSet);
  end;
end;
like image 61
Remy Lebeau Avatar answered Oct 24 '25 07:10

Remy Lebeau


Go to Project Options -> Application -> Orientation

Check Custom Orientation and check one of the Landscape options.

like image 42
sgm Avatar answered Oct 24 '25 06:10

sgm



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!