How to obtain CFStringRef value from iOS API function in Delphi 10.3 Rio


Cannot obtain CFStringRef value from iOS API function (framework) in Delphi 10.3 Rio

// external call bridge function to iOS:
function MIDIObjectGetStringProperty(obj: MIDIObjectRef;
propertyID: CFStringRef;
out str: CFStringRef):OSStatus; cdecl; external libCoreMidi name _PU + ‘MIDIObjectGetStringProperty’;

Function MIDIObjectGetStringProperty (iOS CoreMIDI function) return in str:CFStringRef name of MIDI ports …

How can I obtain value of CFString variable in Delphi? In this example str:CFStringRef value?

I try it in my func.:

function getDisplayName(obj: MIDIEndpointRef):string;
EndPointName: CFStringRef;
//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

Probably EndPointName need to be allocated … else I give AV error. Please got someone solution how obtain ANY CFStringRef value from iOS framework and convert to string? Thanx.


I build crossplatform (iOS, Android, W64) app in Delphi Rio via FireMonkey frameforks api – for CoreMIDI I use this interface

So the externall call and constants are defined in iOSapi.CoreMIDI there:

function MIDIObjectGetStringProperty (obj: MIDIObjectRef; propertyID: CFStringRef; str: CFStringRef) : OSStatus; cdecl; external libCoreMIDI name _PU + ‘MIDIObjectGetStringProperty’;

and iOS pointer const:

function kMIDIPropertyDisplayName: Pointer;
Result := CocoaPointerConst(libCoreMIDI, ‘kMIDIPropertyDisplayName’);

Otherwies compiled app work on real iOS (iPad) very well (reading MIDI message from connected MIDI keyboard) based on this solution

obj: MIDIObjectRef is source pointer from source:= MIDIGetSource(ci);

Problem is calling API function MIDIObjectGetStringProperty. In pointer str: CFStringRef (EndPointName) should be VALUE of MIDIportNAME. I cannot obtain this value and parse to delphi string …

I tried declared this poiter CFStringRef as:

EndPointName: pointer;
EndPointName1: array of Byte;
EndPointName2: TBytes;
EndPointName3: TPtrWrapper;
M: TMarshaller;

and construction as:

SetLength(EndPointName1, 255);
EndPointName3 := M.AllocMem(255);

i := MIDIObjectGetStringProperty(obj, kMIDIPropertyDisplayName , @EndPointNameX);

–> nothing works, AV error !!!

I thing it must be solution how to obtain CFStringRef and convert to delphi string …

Comments are closed.