1
0
Files
aarre
applications
bindings
components
ZVDateTimeCtrls
aboutcomponent
acs
beepfp
chelper
cmdline
cmdlinecfg
colorpalette
csvdocument
epiktimer
fpsound
fpspreadsheet
fractions
freetypepascal
geckoport
gradcontrols
iosdesigner
iphonelazext
examples
HelloWorld
ihelloworld.ico
ihelloworld.lpi
ihelloworld.pas
iArkanoid
pbx
tests
def_buildscript.sh
environment_buildscript.lfm
environment_buildscript.pas
environment_iphone_options.lfm
environment_iphone_options.lrs
environment_iphone_options.pas
ideext.pas
ioptionsdialog.lfm
ioptionsdialog.lrs
ioptionsdialog.pas
iphonebundle.pas
iphoneextoptions.pas
iphoneextstr.pas
iphonelazext.lpk
iphonelazext.pas
iphonelog_form.lfm
iphonelog_form.pas
iphonesimctrl.pas
lazfilesutils.pas
newxibdialog.lfm
newxibdialog.pas
plistfile.pas
project_iphone_options.lfm
project_iphone_options.lrs
project_iphone_options.pas
xcodetemplate.pas
xcodeutils.pas
xibfile.pas
jujiboutils
jvcllaz
kcontrols
lazbarcodes
lclextensions
longtimer
manualdock
mplayer
multithreadprocs
nvidia-widgets
onguard
orpheus
playsoundpackage
poweredby
powerpdf
rgbgraphics
richmemo
richview
rtfview
rx
scrolltext
smnetgradient
spktoolbar
svn
tdi
thtmlport
tparadoxdataset
tvplanit
virtualtreeview
virtualtreeview-new
xdev_toolkit
zlibar
examples
lclbindings
wst
lazarus-ccr/components/iphonelazext/examples/HelloWorld/ihelloworld.pas

94 lines
2.5 KiB
ObjectPascal
Raw Normal View History

program ihelloworld;
{$mode objfpc}{$H+}
{$modeswitch objectivec1}
{$linkframework UIKit}
uses
// you can probably find a number of different iPhoneAll units available online.
// The example is written, using iPhoneAll from https://github.com/genericptr/iOS_8_0
// Once you get the headers don't forget to add to search path for the project
iPhoneAll;
type
TAppDelegate = objcclass(NSObject)
procedure applicationDidFinishLaunching(application: UIApplication); message 'applicationDidFinishLaunching:';
end;
TMyView = objcclass(UIView)
public
procedure drawRect(c: CGRect); override;
end;
const
helloworld = 'Hello world';
// window paint method
procedure TMyView.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 : UIWindow;
ctrl : UIViewController;
myview : TMyView;
{ TAppDelegate }
procedure TAppDelegate.applicationDidFinishLaunching(application: UIApplication);
begin
// application has initialized, now we can create the main window
// initialize window in Objective-C style
mainwindow:=UIWindow.alloc.initWithFrame(UIScreen.mainScreen.bounds);
// creating the root controller
ctrl:=UIViewController.alloc.init;
mainwindow.setRootViewController(ctrl);
myview := TMyView.alloc.init;
myview.setBounds( mainwindow.bounds );
ctrl.setView(myview);
// 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, PChar(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.