基本上我想要实现的是当用户在应用程序的某个部分根据需要更改屏幕旋转时,我有这个为Andriod工作,我不明白为什么它不应该适用于iOS
procedure TForm1.Button1Click(Sender: TObject);
var
ScreenService: IFMXScreenService;
OrientSet: TScreenOrientations;
begin
if TPlatformServices.Current.SupportsPlatformService(IFMXScreenService, IInterface(ScreenService))
then
begin
OrientSet := [TScreenOrientation.soLandscape];//<- Break point set here and line is executed
ScreenService.SetScreenOrientation(OrientSet);
end;
end;
Run Code Online (Sandbox Code Playgroud)
从这里采取:如何在delphi xe5 Firemonkey中使用android开发防止屏幕旋转
ScreenService.SetScreenOrientation已执行且不会引发异常,但方向未更改,我还在Project> Options> Application> Orientation中设置了Enable custom orientation,但这也没有任何效果.
对我来说奇怪的是,如果不支持,那么不应该这样
if TPlatformServices.Current.SupportsPlatformService(IFMXScreenService, IInterface(ScreenService))
Run Code Online (Sandbox Code Playgroud)
回报错误?甚至没有进入开始
我添加了一个测试按钮来检查屏幕方向后,我将其设置为横向
if TPlatformServices.Current.SupportsPlatformService(IFMXScreenService, IInterface(ScreenService))
then
begin
case ScreenService.GetScreenOrientation of
TScreenOrientation.Portrait: ShowMessage('Portrait');
TScreenOrientation.Landscape: ShowMessage('landscape');
TScreenOrientation.InvertedPortrait: ShowMessage('Inverted-Portrait');
TScreenOrientation.InvertedLandscape: ShowMessage('Inverted-Landscape');
else ShowMessage('not set');
end;
end;
Run Code Online (Sandbox Code Playgroud)
如果在将它设置为横向之后它在纵向中,它仍然会说肖像
更新1:我也试过改变
OrientSet := [TScreenOrientation.soLandscape] // <- Deprecated
Run Code Online (Sandbox Code Playgroud)
至
OrientSet := …Run Code Online (Sandbox Code Playgroud) 如果未设置我的对象中的某个属性,我希望能够创建编译器错误/警告.假设我有以下课程:
interface
type
TBarkevent = procedure (Bark : String) of object;
TDog = class
private
FOnBark : TBarkevent;
procedure SetBark(const Value: TBarkevent);
function GetBark: TBarkEvent;
public
procedure Bark;
property OnBark : TBarkEvent read GetBark write SetBark;
constructor Create;
end;
implementation
{ TDog }
procedure TDog.Bark;
begin
if Assigned(OnBark) then
OnBark('Woof!')
end;
constructor TDog.Create;
begin
end;
function TDog.GetBark: TBarkEvent;
begin
Result := FOnBark;
end;
procedure TDog.SetBark(const Value: TBarkevent);
begin
FOnBark := Value;
end;
Run Code Online (Sandbox Code Playgroud)
我TDog在另一个单位中使用这个类,如下所示:
var
Dog : TDog;
begin …Run Code Online (Sandbox Code Playgroud)