[fpc-devel] Creating a Cocoa Application

Felipe Monteiro de Carvalho felipemonteiro.carvalho at gmail.com
Sun Jan 6 19:03:11 CET 2008


thanks, ok, I think I'm almost getting it to work.

I translated enougth headers to call NSApplicationLoad and
NSRunAlertPanel, but I got stuck at the @"string" syntax. I tryed to
just define PNSString as a generic pointer and pass a PChar to it, but
it doesn't work, the application crashes with messages that the
autorelease pool isn't installed:

2008-01-06 19:01:46.396 cocoamsgbox[1752] *** _NSAutoreleaseNoPool():
Object 0x318310 of class NSCFString autoreleased with no pool in place
- just leaking

Here is my current code:

program cocoamsgbox;

{$mode objfpc}{$H+}

uses
  objc, appkit;

const
  Str_NSAutoreleasePool = 'NSAutoreleasePool';
  Str_alloc = 'alloc';
  Str_init = 'init';
  Str_release = 'release';
var
  { classes }
  NSAutoreleasePoolId: id;
  { objects }
  pool: id;
begin
//  NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
  NSAutoreleasePoolId := objc_getClass(PChar(Str_NSAutoreleasePool));
  pool := objc_msgSend(NSAutoreleasePoolId,
sel_registerName(PChar(Str_alloc)), []);
  objc_msgSend(NSAutoreleasePoolId, sel_registerName(PChar(Str_init)), []);

  NSApplicationLoad();
  { uses a default "OK" button and no alternate buttons }
//    NSRunAlertPanel(@"This is the title", @"This is the message",
nil, nil, nil);
  NSRunAlertPanel(PChar('This is the title'), PChar('This is the
message'), nil, nil, nil, []);

//  [pool release];
  pool := objc_msgSend(NSAutoreleasePoolId,
sel_registerName(PChar(Str_release)), []);
end.

thanks,
-- 
Felipe Monteiro de Carvalho



More information about the fpc-devel mailing list