Archive for February, 2012

Targeting iOS with ObjPas

Tuesday, February 28th, 2012

Today I looked at using ObjPas for XCode 4. The documentation is a little stale, but Phil Hess has provided an excellent guide to getting started as well as why you might want to use ObjPas/FPC with XCode compared to FireMonkey or Objective-C.

When I initially created a new project from the template as per the tutorial, I couldn’t run it. XCode reported an error and I had to scan through the shell script to actually discover it was unable to create a file. I discovered the path where it was trying to create the file didn’t exist, and googled the error to find a discussion on the exact problem.

After fixing the Create File problem as suggested by Simon Chol as follows:

I replace just the one character (armv6 -> armv7) in section
Targets | Items 0 | SharedSettings | FPC_ARM_SHARED_OPTIONS
/users/[...]/Library/Developer/Xcode/Templates/Objective Pascal/iOS/Objective Pascal App
/Cocoa Touch Application.xctemplate/TemplateInfo.plist

I then had to manually paste the following code with the [window release]; selected:

- (void)dealloc
[window release];
[super dealloc];

I also had to turn off Automatic Reference Counting (ARC) since it is checked by default when creating the project, and I had left it checked, so the compiler complained about the presence of NSAutoreleasePools.

My initial impression was that this approach is far better than using FireMonkey in terms of meeting Apple’s UI requirements, but since there is no code insight, or completion in XCode for ObjPas and you have to declare Outlets and Actions twice (once in Objective-C and once in ObjPas) this would get rather tedious rather quickly.

If you’re going to use the Pascal for development I think the XE2 approach of using XCode for compiling and debugging only is a much better approach. ┬áIt also opens up the possibility to one day develop for the iPhone solely on a PC when EMB finally releases their new compiler that supports ARM.