IPhone Laz Extension

This is an old revision of IPhone Laz Extension, edited by Skalogryz at . The current revision is 65273.

/* iArkanoid */

This article applies to iOS only.

See also: Multiplatform Programming Guide

About

iPhone Laz extension is Lazarus IDE extension that's designed to simplify iPhone applications development.

Before you use the extension, it's recommended to learn the page about iPhone/iPod development.

The extension does NOT provide another LCL WidgetSet (like Carbon or Cocoa) nor requires to use any.

Author

Dmitry 'skalogryz' Boyarintsev

email: skalogryz dot lists at gmail dot com

License

modified LGPL (same as the FPC RTL and the Lazarus LCL). You can contact the author if the modified LGPL doesn't work with your project licensing.

Download

The latest stable release can be found at svn:

svn co https://lazarus-ccr.svn.sourceforge.net/svnroot/lazarus-ccr/components/iphonelazext

Change Log

Dependencies / System Requirements

Status: Beta

Known Issues:

 Application.Title:='MyApp';

It must be deleted manually

To do:

Installation

In order to develop for iPhone or iPod, you'll need arm FPC compiler with rtl and packages installed in the system. There're 2 ways to do it: built manually via SVN or installed from a special FPC arm package. Both ways are described here.

You don't need to install ARM compiler or packages, if you're planning to use iPhone simulator only.

How to use

Common usage

iPhone Simulator

The installation is always performed then you try to build the project.

iPhone simulator apps require special environment, created by the simulator or they will fail with "trace error" if run in pure OSX. To make the simulator Run everytime you're running the application, select in menu "Run->Run parameters..." check "Use launching application" put there

'/Developer/Platforms/iPhoneSimulator.platform/Developer/Applications/iPhone Simulator.app/Contents/MacOS/iPhone Simulator'

Note: the location of iPhone simulator.app may vary, depending on the iPhone SDK installation path.

It's not required, but you'll need to launch iPhoneSim manually otherwise.

It's possible, that iPhone sim also starts the required application (as Xcode does), but this possibility is undocumented by Apple. You can use it on your own risk. Please refer to http://github.com/jhaynie/iphonesim

Project to Xcode

There's not way to install an application to iPhone, but using Xcode (or purchasing it via iTunes). (Jailbreaks have their own way, not used by the package). The package provides an utility to generate an Xcode project from Lazarus project.

Note:

Examples

The extension also includes a few sample projects. (see examples dir at the iphonelazext directory)

Hello World

The sample requires a objective-p compiler (fpc 2.5.1 or higher) with cocoaint packages compiled for iPhone

 program project1;
 
 {$mode objfpc}{$H+}
 {$modeswitch objectivec1}
 {$linkframework UIKit} 
 
 uses
   iPhoneAll, CGContext, CGGeometry, CFString; 
 
 type
   TAppDelegate = objcclass(NSObject)
     procedure applicationDidFinishLaunching(application: UIApplication); message 'applicationDidFinishLaunching:';
   end; 
 
   TMyWindow = objcclass(UIWindow)
   public
     procedure drawRect(c: CGRect); override;
   end;
 
 const
   helloworld = 'Hello world'; 
 
 // window paint method
 procedure TMyWindow.drawRect(c: CGRect);
 var
   cg : CGContextRef;
 begin
   // getting current context
   cg:=UIGraphicsGetCurrentContext;
   // setting back ground color
   CGContextSetRGBFillColor(cg, 0, 0, 0.5, 1);
   CGContextFillRect(cg, c); 
 
   // rotating up-side down context
   CGContextTranslateCTM(cg, 0, c.size.height);
   CGContextScaleCTM(cg, 1, -1); 
 
   // setting text color
   CGContextSetRGBFillColor(cg, 1, 1, 0, 1);
   CGContextSetRGBStrokeColor(cg, 1, 1, 0, 1);
   // setting font  (must set any)
   CGContextSelectFont(cg, 'Helvetica', 30, kCGEncodingMacRoman);
   // rendering text
   CGContextShowTextAtPoint(cg, 0, c.size.height-50, helloworld, length(helloworld));
 end;
 
 var
   mainwindow : TMyWindow;
 
 { TAppDelegate }
 
 procedure TAppDelegate.applicationDidFinishLaunching(application: UIApplication);
 begin
   // application has initialized, now we can create the main window
   mainwindow:=TMyWindow(TMyWindow.alloc);
   // initialize window in Objective-C style
   mainwindow := TMyWindow(mainwindow.initWithFrame (UIScreen.mainScreen.bounds));
   // activate and show the window
   mainwindow.makeKeyAndVisible;
 end;
 
 function NSStr(const s: string): NSString;
 begin
   // converting string to NSString (CFStringRef and NSString are interchangable)
   Result:=NSString( CFStr(PChar(s)));
 end;
 
 var
   pool    : NSAutoreleasePool;
 begin
   // initialize foundation memory manger (aka autorelease pool)
   pool := NSAutoreleasePool.alloc.init;
   // launching main application loop
   ExitCode:=UIApplicationMain(argc, argv, nil, NSSTR('TAppDelegate'));
   // according to docs the UIApplicationMain never returns,
   // but still the code present in the Obj-C main.m files
   pool.release;
 end.

The result would look like:

iArkanoid

Written from scratch simple arkanoid game UIKit and GoreGraphics games for iPhone/iPod.