delphi - 使用 IFMXImageManagerService 时 iOS 上的访问冲突
问题描述
我正在使用这个简单的代码:
procedure TForm1.Button1Click(Sender: TObject);
var servicios: IFMXImageManagerService;
i:integer;
begin
i:=servicios.GetCount;
showmessage(inttostr(i));
end;
我收到一条 iOS 消息:“地址 0000000104BB0460 的访问冲突,访问地址 00000000000000000”。
我尝试使用 IFMXImageManagerService 的所有操作都会触发该违规消息。
请问,有人知道为什么吗?
谢谢!
解决方案
你没有初始化servicios
指向任何有意义的东西,所以当然调用它的任何方法,比如servicios.GetCount()
,都会失败。
您需要使用TPlatformServices.GetPlatformService()
或TPlatformServices.SupportsPlatformService()
来初始化servicios
. Embarcadero 的文档对此进行了解释:
要使用平台服务,您必须:
- 向您的单元添加对声明您的服务的单元的引用,例如 FMX.Platform。
- 以目标平台服务为参数调用
TPlatformServices.SupportsPlatformService
,判断运行时是否支持指定平台服务。- 如果
SupportsPlatformService
返回 True,则用于TPlatformServices.GetPlatformService
访问实际的平台服务,并适当地转换返回的服务。您也可以使用SupportsPlatformService
来获取服务。
尝试这个:
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;
推荐阅读
- java - 为什么 sun.swing.FilePane 可以强制转换为 javax.swing.table?
- r - R Markdown文件不会编织
- arrays - Powershell:indexOf row where column = searchstring
- mysql - 如何在存储过程 MYSQL 中将“SELECT *”的结果转换为数组?
- android - 无法使用 Gson 将字符串解析为 JSONArray
- python - 需要从 Python 中的用户输入创建正则表达式模式
- ruby-on-rails - 狂欢中的 NoMethodError::
- c++ - 使用 pimpl idiom 移动操作
- python - 如何从具有不同 dtype 的 numpy 数组的交错中获取字节?
- javascript - Webpack 不会呈现自定义字体