2008-09-29 00:47:50 +00:00
|
|
|
{
|
|
|
|
texteditor.pas
|
|
|
|
|
|
|
|
This example shows how to create a simple text editor with PasCocoa
|
|
|
|
|
|
|
|
This example project is released under public domain
|
|
|
|
|
|
|
|
AUTHORS: Felipe Monteiro de Carvalho
|
|
|
|
}
|
|
|
|
program texteditor;
|
|
|
|
|
|
|
|
{$mode delphi}
|
|
|
|
|
|
|
|
{$linkframework Cocoa}
|
|
|
|
{$linklib objc}
|
|
|
|
|
|
|
|
uses
|
|
|
|
Math,
|
|
|
|
objc, ctypes, MacOSAll, AppKit, Foundation,
|
2008-10-06 02:46:47 +00:00
|
|
|
{$ifndef WITHOUT_PKG}cocoa_pkg,{$endif}
|
|
|
|
controller, model, view, mytoolbar;
|
2008-09-29 00:47:50 +00:00
|
|
|
|
|
|
|
var
|
|
|
|
pool: NSAutoreleasePool;
|
|
|
|
begin
|
|
|
|
{ Avoids arithmetic exceptions in Objective-C code }
|
|
|
|
|
|
|
|
SetExceptionMask([exInvalidOp, exDenormalized, exZeroDivide, exOverflow, exUnderflow, exPrecision]);
|
|
|
|
|
|
|
|
{ Creates the AutoreleasePool }
|
|
|
|
pool := NSAutoreleasePool.Create;
|
|
|
|
|
|
|
|
{ Creates the application NSApp object }
|
|
|
|
NSApp := NSApplication.sharedApplication;
|
|
|
|
|
2008-10-06 22:40:47 +00:00
|
|
|
// NSBundleNib.loadNibNamed_owner(CFStringCreateWithPascalString(nil, 'applemenu', kCFStringEncodingUTF8), NSApp.Handle);
|
|
|
|
|
2008-10-08 11:28:15 +00:00
|
|
|
{ Initializes the controller and the model. Must be before the view to
|
|
|
|
attach the events (controller) and guarantee that resources are loaded (model) }
|
2008-09-29 00:47:50 +00:00
|
|
|
|
2008-10-08 11:28:15 +00:00
|
|
|
myController := TMyController.Create();
|
2008-09-29 00:47:50 +00:00
|
|
|
myModel := TMyModel.Create();
|
|
|
|
|
2008-10-06 02:46:47 +00:00
|
|
|
{ Initializes the view object }
|
2008-09-29 00:47:50 +00:00
|
|
|
|
2008-10-06 02:46:47 +00:00
|
|
|
myView := TMyView.Create;
|
|
|
|
myView.CreateUserInterface;
|
2008-09-29 00:47:50 +00:00
|
|
|
|
|
|
|
{ Enters main message loop }
|
|
|
|
|
2008-10-06 02:46:47 +00:00
|
|
|
myView.MainWindow.orderFrontRegardless;
|
|
|
|
|
2008-09-29 00:47:50 +00:00
|
|
|
NSApp.setDelegate(myController.Handle);
|
|
|
|
|
|
|
|
NSApp.run;
|
|
|
|
|
|
|
|
{ Releases all objects }
|
|
|
|
|
|
|
|
myController.Free;
|
|
|
|
myModel.Free;
|
|
|
|
myView.Free;
|
|
|
|
|
|
|
|
{ Releases the AutoreleasePool }
|
|
|
|
pool.Free;
|
|
|
|
end.
|
|
|
|
|