首页 > 解决方案 > 使用 IFMXImageManagerService 时 iOS 上的访问冲突

问题描述

我正在使用这个简单的代码:

procedure TForm1.Button1Click(Sender: TObject);
var servicios: IFMXImageManagerService;
    i:integer;
begin
    i:=servicios.GetCount;
    showmessage(inttostr(i));
end;

我收到一条 iOS 消息:“地址 0000000104BB0460 的访问冲突,访问地址 00000000000000000”。

我尝试使用 IFMXImageManagerService 的所有操作都会触发该违规消息。

请问,有人知道为什么吗?

谢谢!

标签: delphi

解决方案


你没有初始化servicios指向任何有意义的东西,所以当然调用它的任何方法,比如servicios.GetCount(),都会失败。

您需要使用TPlatformServices.GetPlatformService()TPlatformServices.SupportsPlatformService()来初始化servicios. Embarcadero 的文档对此进行了解释:

FireMonkey 平台服务

要使用平台服务,您必须:

尝试这个:

uses
  ..., FMX.Platform, FMX.MediaLibrary;

procedure TForm1.Button1Click(Sender: TObject);
var
  servicios: IFMXImageManagerService;
  i: integer;
begin
  if TPlatformServices.Current.SupportsPlatformService(IFMXImageManagerService, IInterface(servicios)) then
  begin
    i := servicios.GetCount;
    ShowMessage(IntToStr(i));
  end else
    ShowMessage('Image Manager not supported');
end;

推荐阅读