我找到了以下代码来防止屏幕旋转,但在编译时,我会得到一堆未声明的标识符:IFMXScreenService, TPlatformServices
。
很明显这是因为缺少单位。但我找不到它是什么单位。
代码:
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;
任何帮助都非常感谢。
更新:
缺少的单元是
FMX.Platform
。但是当我现在尝试编译时,我得到一个错误:\\android\\debug\\libproject.so: open: permission denied
最佳答案
将FMX.Platform
添加到uses
子句中,并去掉对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;