ios - 如何从 Delphi 10.3 Rio 中的 iOS API 函数获取 CFStringRef 值
问题描述
无法CFStringRef
从 Delphi 10.3 Rio 中的 iOS API 函数(框架)获取值
// external call bridge function to iOS:
function MIDIObjectGetStringProperty(obj: MIDIObjectRef;
propertyID: CFStringRef;
out str: CFStringRef):OSStatus; cdecl; external libCoreMidi name _PU + 'MIDIObjectGetStringProperty';
函数MIDIObjectGetStringProperty
(iOS CoreMIDI 函数)str:CFStringRef
以 MIDI 端口的名称返回...
如何CFString
在 Delphi 中获取变量的值?在这个例子中str:CFStringRef
值?
我在我的函数中尝试它:
function getDisplayName(obj: MIDIEndpointRef):string;
var
EndPointName: CFStringRef;
i:integer;
begin
//EndPointName:= nil; // when I assign nil value, function return i=-50 otherwise raise Access Violation error ...
i := MIDIObjectGetStringProperty(obj, kMIDIPropertyDisplayName , EndPointName); --> AV error !!!
//in EndPointName should be returned CFStringRef value from iOS
getDisplayName := CFToDelphiString(EndPointName); // convert to string
end;
可能EndPointName
需要分配...否则我给出 AV 错误。请有人解决如何CFStringRef
从 iOS 框架中获取任何值并转换为字符串?谢谢。
补充:
我通过 FireMonkey frameforks api 在 Delphi Rio 中构建跨平台(iOS、Android、W64)应用程序 - 对于 CoreMIDI,我使用这个接口https://github.com/FMXExpress/ios-object-pascal-wrapper/blob/master/iOSapi.CoreMIDI .pas
所以外部调用和常量是在 iOSapi.CoreMIDI 中定义的:
function MIDIObjectGetStringProperty (obj: MIDIObjectRef; propertyID: CFStringRef; str: CFStringRef) : OSStatus; cdecl; external libCoreMIDI name _PU + 'MIDIObjectGetStringProperty';
和 iOS 指针常量:
function kMIDIPropertyDisplayName: Pointer;
begin
Result := CocoaPointerConst(libCoreMIDI, 'kMIDIPropertyDisplayName');
end;
基于此解决方案https://pjstrnad.com/reading-data-midi-keyboard-ios-probably-also-mac/
obj: MIDIObjectRef 是来自 source:= MIDIGetSource(ci) 的源指针;
问题是调用 API 函数 MIDIObjectGetStringProperty。在指针 str 中:CFStringRef (EndPointName) 应该是 MIDIportNAME 的 VALUE。我无法获取此值并解析为 delphi 字符串...
我尝试将此指针 CFStringRef 声明为:
var
EndPointName: pointer;
EndPointName1: array of Byte;
EndPointName2: TBytes;
EndPointName3: TPtrWrapper;
M: TMarshaller;
和建设为:
SetLength(EndPointName1, 255);
GetMem(EndPointName2,255);
EndPointName3 := M.AllocMem(255);
i := MIDIObjectGetStringProperty(obj, kMIDIPropertyDisplayName , @EndPointNameX);
--> 没有任何效果,AV 错误!!!
我认为它必须是如何获取 CFStringRef 并转换为 delphi 字符串的解决方案......
解决方案
在kMIDIPropertyDisplayName
iOS 上已损坏,但您可以将其替换为 CFSTR('displayName')。这个对我有用。所以你的函数看起来像这样:
function getDisplayName(aEndPointRef: MIDIEndpointRef):string;
var
LEndPointName: CFStringRef;
i:integer;
begin
getDisplayName := 'MIDI endpoint';
LEndPointName:= nil;
i := MIDIObjectGetStringProperty(aEndPointRef, CFSTR('displayName'), LEndPointName);
if (i=0) and (LEndPointName<>nil) then
getDisplayName := CFStringRefToStr(LEndPointName);
end;
Macapi.CoreFoundation
将and添加Macapi.Helpers
到您的 USES 子句以访问CFSTR
andCFStringRefToStr
推荐阅读
- php - 一个 PHP 函数,用于从数据库中获取 pdf 并在屏幕上显示
- extjs - ExtJS中网格中的上下文菜单
- serial-port - 从 ESP32 到 Fanstel BC805M (nRF52805M) 的 AT 命令不起作用
- bash - Amazon S3 下载失败:RequestTimeTooSkewed
- spring - Spring webclient exchangeToFlux()不发出HTTP请求
- python - Pycharm 进程以退出代码 0 而不是实际输出完成
- node.js - 如何将文件从 NodeJs 服务器发送到输入字段
- ansible - 如何遍历具有变量索引的ansible列表?
- regex - 如何防止 Jenkins 删除 JSON 参数中的双引号以与 AWS CLI 一起使用?
- flutter - Flutter - 正确删除应用内购买的广告