Implementing missing iOS frameworks

The challenge

As I mentioned in previous posts, I’m just writing a game for an iOS under Delphi XE-5.

Well on the begging it was looking really nice and easy, but there are some catches.

XcodeFirst Delphi doesn’t support multi-touch. This was handled thanks to support of Iztok Kacin.

Second catch was MIDI.

I found that iOS can play MIDI by this article, but from Delphi I couldn’t call it, because “god knows why” Embarcadero created support for some of the frameworks under Delphi.

So I was digging and digging and I found out that it’s actually relatively simple to add missing frameworks to Delphi.

The solution

Embarcadero did that for some of them and Xcode gives header files to each of the framework.

I just compared the Delphi .PAS unit with the original .H unit to get the concept.

I implemented few functions manually and by that managed to play a MIDI file at my app.

But as you can imagine whole library is more then 5 functions. It’s a thousand lines of code actually.

Lot of work… but I’m a programmer and when there is lot of work I have usually a computer to do it (for cleaning dishes I have wife muhaha).

And I wrote an application that is doing the conversion.

It took me whole day and night to get first working version, but HOORAY it’s working and I can compile one iOS unit directly by Delphi without any error.

I prepared special page for this project, to put there updated. I’m calling it:
Delphi implementation of missing iOS frameworks

The nasty technical details

Unfortunately this doesn’t mean that the code is correct.

Nice thing on my solution is that if I have there a mistake, this mistake will be all over at every place where that specific type of code was used. If someone will find it, I can correct my tool reexport the units and publish newer and better version.

One of key thing I have to do was implementation of the compilation directives.

There is lot of code like this:

  #if !defined(CA_PREFER_FIXED_POINT)
            #define CA_PREFER_FIXED_POINT 0
            #define CA_PREFER_FIXED_POINT 1
        #define CA_PREFER_FIXED_POINT 0

which my tool must understand otherwise there will be lot of crap.

So I did an implementation of this, but I’m sure that there will be more work as I’ll convert more units.

The next problem was the records and the unions:

struct AUNodeInteraction
	UInt32	nodeInteractionType;

		AUNodeConnection	connection;		
		AUNodeRenderCallback	inputCallback;

	} nodeInteraction;

Well I’m not ObjectiveC programmer and I was working with C few years ago.

But the internet is just great thing I found this article that helped me really a lot. Thank you Rudi!

The result

I have now working basic version of MIDI at my iOS application and I want to add more units so any Delphi programmer can use all the iOS features.

I’ll appreciate the help of other people – if you can use the units and let me know if the work for you or point me the error you found, it would be great.

Enjoy it.


  1. Checco says:

    Interesting article. How far have you gone with your translations? I have an iOS project that needs to be developed and I’m not sure whether I’ll upgrade to XE7 or just learn Objective-C/Swift. I need to start with ExternalAccessory and not sure what else from there. Just a frustration that they aren’t all included!

    • pjstrnad says:

      I can translate most of the C headers but not C++ (objects).

      From my experience you can do almost anything from Delphi, but limitation is the visual. The application is just not so nice as the native iOS.

      Objective-C looks to me terrible, I think the Swift can be nice. Want to try it my self.

Leave a Reply

Your email address will not be published. Required fields are marked *