Screen orientation on iOS

  

Per this question in Delphi an FMX app can be selectively forced into landscape or portrait with code like this:

procedure TForm1.Chart1Click(Sender: TObject);
begin
if Application.FormFactor.Orientations = [TScreenOrientation.Landscape] then
Application.FormFactor.Orientations := [TScreenOrientation.Portrait]
else
Application.FormFactor.Orientations := [TScreenOrientation.Landscape];
end;
end;

I can’t figure out how to translate this code above to C++Builder. I tried the following code based on this post but it gives access violation on both iOS and Android:

void __fastcall TForm1::Button1Click(TObject *Sender)
{
_di_IInterface Intf;
if (TPlatformServices::Current->SupportsPlatformService(__uuidof(IFMXScreenService), Intf))
{
_di_IFMXScreenService ScreenService = Intf;
TScreenOrientations Orientation;
Orientation << TScreenOrientation::Landscape;
ScreenService->SetScreenOrientation(Orientation);
}
}

Is this even doable in FMX with C++Builder?

Comments are closed.