如何在Delphi 10.3中从iOS API函数中获取CFStringRef值

如何在Delphi 10.3中从iOS API函数中获取CFStringRef值,ios,delphi,frameworks,firemonkey,Ios,Delphi,Frameworks,Firemonkey,无法从Delphi 10.3中的iOS API函数(框架)获取CFStringRef值 // external call bridge function to iOS: function MIDIObjectGetStringProperty(obj: MIDIObjectRef; propertyID: CFStringRef; out str: CFStringRef):OSStatus; cdecl; external libCoreMidi

无法从Delphi 10.3中的iOS API函数(框架)获取
CFStringRef

// 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端口名称中返回

如何在Delphi中获取
CFString
变量的值?在本例中,
str:CFStringRef
value

我试着用我的功能

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错误。请找人解决如何从iOS框架中获取任何
CFStringRef
值并转换为字符串的问题?塔克斯

加上:

我通过FireMonkey frameforks api在Delphi Rio中构建跨平台(iOS、Android、W64)应用程序-对于CoreMIDI,我使用此接口

因此,外部调用和常量在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;
基于此解决方案,Otherwies编译的应用程序在真正的iOS(iPad)上工作得非常好(从连接的MIDI键盘读取MIDI消息)

obj:MIDIObjectRef是源的源指针:=MIDIGetSource(ci)

问题是调用API函数MIDIObjectGetStringProperty。在指针str中:CFStringRef(EndPointName)应该是MIDIportNAME的值。我无法获取此值并解析为delphi字符串

我尝试将此点声明为:

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字符串

在iOS上,
kMIDIPropertyDisplayName
已损坏,但您可以将其替换为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;
函数getDisplayName(aEndPointRef:MIDIEndpointRef):字符串; 变量 LEndPointName:CFStringRef; i:整数; 开始 getDisplayName:=“MIDI端点”; LEndPointName:=nil; i:=MIDIObjectGetStringProperty(aEndPointRef、CFSTR('displayName')、LEndPointName); 如果(i=0)和(LEndPointNamenil),则 getDisplayName:=CFStringRefToStr(LEndPointName); 结束;
Macapi.CoreFoundation
Macapi.Helpers
添加到您的USES子句中,以访问
CFSTR
CFStringRefToStr

如何获得obj和kMIDIPropertyDisplayName?显示我们自己无法确定的所有代码非常重要。XE不支持IOS。感谢您的反应。我添加了更多信息。请停止引用XE。该版本的Delphi早于移动支持。您使用的是10.3里约热内卢。请改正课文。抱歉更正。。。