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 02:46:47 +00:00
|
|
|
{ Initializes the model object,
|
|
|
|
must be after the view so that the resources are loaded }
|
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
|
|
|
|
2008-10-06 02:46:47 +00:00
|
|
|
{ The controller needs to be the last to be creates for an unknown reason,
|
|
|
|
and we can only attach the events after the controller is created }
|
|
|
|
|
|
|
|
myController := TMyController.Create();
|
|
|
|
|
|
|
|
myView.AttachEventHandlers();
|
2008-10-06 13:26:48 +00:00
|
|
|
myToolbarController.AttachEventHandlers(); // Created in 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.
|
|
|
|
|