Pascal Development on OS X
Objective Pascal

FPC now supports an Objective-C compatible dialect appropriately titled Objective Pascal. Visit ObjectivePascal.com which is the new home page for the language.

The most recent information on installing compilers for both Cocoa and iOS development can found on the Free Pascal Objective Pascal wiki.

There is also a Mac installer application which will build the most recent version of the compiler for Cocoa development after following a few steps.

Version 1.0.2 (7/16/10):
	- The installer now accepts a base version (instead of being fixed at 2.2.4) so you can change this manually when new versions of FPC are released.
	- There is a "Copy Headers" option which will copy the translated headers from SVN to the Objective Pascal directory you specified.
	- Universal Binary (OS 10.5 and higher).
	
Version 1.0.1:
	- Widened status label.
	- Added -p to the cp command when copying files to the ObjectivePascal directory.
	

PascalGladiator Examples

  • CircleView. Pascal port of Apple's CircleView example by Ryan Joseph. Shows how to use the components of the Cocoa text system to draw a custom NSView.
  • OutlineView. Pascal port of Apple's OutlineView example by Ryan Joseph. Shows the most basic implementation of NSOutlineView using the file system as a data source.
  • MiniBrowser. Pascal port of Apple's MiniBrowser WebKit API example by Ryan Joseph. This requires at least revision 13831 of WebKit headers from SVN.
  • NIBWindows. This was an example project I made but corrected by Gorazd Krosl to more Cocoa-ish. ;)
  • PLuaTerminal. Simple terminal for the lua programming language by Gorazd Krosl.
  • TemperatureConverter. Pascal version of the Apple Cocoa tutorial application for beginners by Gorazd Krosl.
  • FPCEventManager. Simple CoreData document based application, a port of Apple's EventManager by Gorazd Krosl.

TextMate Examples

Same as the examples for PascalGladiator but ported to TextMate project format (requires the Pascal TextMate bundle).


Xcode Examples

  • Pascal Cocoa Templates. Xcode project templates by Gorazd Krosl that can be installed into Xcode. There is a read me file included with instructions on how to install and compile the projects.
  • TemperatureConverter. Pascal version of the Apple Cocoa tutorial application for beginners by Gorazd Krosl.

Library Examples

  • RegexKitLite. Pascal port of RegexKitLite by Gorazd Krosl. A framework is supplied for linking which must be placed inside the applications bundle in the Frameworks folder. The example contains only a single unit which is the complete interface to the framework.

iPhone Examples

These examples require the iPhone SDK (from Apple) and translated Pascal interfaces to run (which I can not distribute, see the script above). As of version 0.7.2 PascalGladiator supports a target for compiling bundles which will run in the iPhone simulator but Xcode and certificate ($99) is still required for device targets.

  • iArkanoid. This is a test game by Dmitry 'skalogryz' Boyarintsev which shows how to make a basic iPhone app using CoreGraphics.
  • HelloWorldPascaliPhone. Pascal version of Apple's "Hello World" example (in Xcode project) by Scott Knapp.

The most current Cocoa headers (parsed from their respective Cocoa frameworks) which compile with the latest version of the compiler can be download from the FPC SVN repository here.

Because it against Apples user agreement to distribute iOS headers in translated form they must be parsed manually. There is always a parser script (which invokes the framework parser and patches any errors) in the FPC source distribution downloaded from SVN. To learn how use the script visit the Objective Pascal Wiki.

Applications compiled outside of Xcode can be submitted to the Mac App Store after following these steps and running the installation script. Before continuing to compile anything read the Apple submission checklist and prepare your account and other details.

Requirements for the script:

  • Download the Application Tools package from Apples website or Xcode 3.2.5 which includes the tools as you will need Application Loader to submit the binary. You must be a registered Apple developer and pay an annual $99 fee before you can submit to the Mac App Store.
  • You must have created 2 certificates using the Developer Certificate Utility. You will need to create both the Application and Installer certificates which will be presented as options if you are a registered developer.

Requirements for compiling and building:

  • First read the official Apple submission guidelines and be sure to comply with all points.
  • Compile the final binary to submit with: -gw -godwarfsets -Xg -O2.
  • Universal or PPC binaries are not accepted so you must compile all binaries using only ppc386.
  • Any helper apps inside the main bundle should be Intel only binaries, reside in /Contents/Library/LoginItems and be compiled with optimization using -O2.

Script usage

-path: 		Path to the application bundle.
-sign: 		Developer signature for code signing which starts with "3rd Party Mac Developer Application:" (this can be found in Keychain Access under My Certificates). Do NOT include the aforementioned prefix only text following the colon without preceding spaces.
-install: 	The install path of the .pkg file (defaults to /Applications which is required by Apple).
-dsym: 		Path to a debugging .dSYM file (for example /path/to/Main.dSYM).
-launch: 	The Application Loader will be launched upon completion of the script.
-password: 	Password to the currently logged in OS X user for testing the package installation. If no password is provided the verification process will be skipped.
	

Download the script here. The script is written in PHP so to execute in the terminal use the command php appstore.php. If you run the script with no parameters the usage will be displayed along with other instructions.

The first step to developing for iOS is building the ARM and iOS simulator compilers. The most recent information on this process can found on the Free Pascal Objective Pascal wiki. Before continuing make sure you have installed the compilers successfully.

Once you have compiled a binary you need to install the application to the device via Xcode. This step requires you register with the iPhone developer program and pay an annual fee of $99. After you registration is accepted (this will take a few days) you will be able to create a certificate via the developer web site (Provisioning Portal) which you will download and install into Xcode. This is a rather long process actually and involves many steps but the site will walk you through all of them. Finally after the certificate has been installed successfully in Xcode, running iPhone projects with a device target will install the application onto said device.

This multi-step process is automated (you never need to use Xcode manually once configured) with a script found here. To run the script use a command like: php install_iphone_app.php -binary="path/to/binary" -project="path/to/iphone_template" -config="Debug" -dev="John Doe (SDJKLD9D8S9)" which will build the Xcode project, copy the FPC binary, code sign the binary and resources then run the project from Xcode via AppleScript thus installing the application.

Requirements

  1. Create an Xcode iPhone project. In Xcode create a new project using any iPhone template then delete all source files and resources (besides main.m). Copy any resources and info.plist files into the Xcode project as they will be copied into the application bundle when it is built (you can also copy files directly into the application bundle). Make sure you select Debug as the active configuration and any SDK "device" named SDK for active SDK.
  2. Get the iPhone developer string. Build the project and then inspect the Build Results window. In the code sign item copy the text after iPhone Developer: (see the screen shot for help). This string will be used as the -dev option (see below).

Script usage

-config: 	Active configuration in Xcode project (Debug or Release).
-binary: 	Path to ARM binary compiled with FPC.
-project: 	Path to Xcode iPhone project.
-dev: 		iPhone Developer as in the Xcode code sign command. Example: John Doe (DKJF87DHSJKD).
	
Pascal IDE's

Currently there are a few options of Pascal IDE's for OS X which support FPC.

TextMate for Pascal

The Pascal.tmbundle TextMate bundle adds syntax support for standard, object and Objective Pascal dialects along with compiler utilities for FPC and GDB terminal support which together make a complete IDE experience. TextMate is a simple, yet very powerful editor and when used as an IDE much easier to learn than Xcode. Most importantly TextMate is highly extensible so you can control how it works for you.

You can learn more about Pascal.tmbundle here.

Xcode Integration Kit

Included with every FPC distribution for OS X there is an Xcode integration kit that allows it to compile FPC applications (you have the Xcode developer tools installed first). Because Xcode was basically hacked to work for FPC the syntax support (and code navigation) is poor and for a beginner who isn't familiar with the build settings, very prone to errors. However, it's very stable, has a good project manager and debugger.

You can download the latest FPC version here which includes the integration kit.

PascalGladiator

PascalGladiator was made to be like CodeWarrior with a simplified feature set including: rich syntax styling, code navigation and built-in project manager. It's been difficult for me to manage a project of this size in my spare so it doesn't get updated often and isn't very stable but it's easier to use than Xcode and built specifically for FPC so new users won't have many problems configuring it.

You can learn more about PascalGladiator here.

Lightweight IDE

Lightweight IDE has a strong focus on being simple and is reminiscent of THINK Pascal and the OS 9 days.

You can get more information on Lightweight IDE here

Source Code

These units and API's are being offered as-is for reference and education but the functionality isn't very well documented. Some of these units require Objective Pascal and are missing low-level system units needed to compile but can still be used to study if you found anything interesting.

Toolbox

UNIX

Carbon Wrappers

Carbon GUI

Other API's


© 2011 Ryan Joseph

myspace profile view counter