-1

How can I create a NSWindow in code in Delphi for OSX?

Here is what I've tried:

uses Macapi.AppKit,Macapi.CocoaTypes;

...

var
  NW : NSWindow;
begin
  Nw := TNSWindow.Create;
  Nw.initWithContentRect(MakeNSRect(100,100,250,250), NSBorderlessWindowMask, NSBackingStoreBuffered, True);

But on the initWithContentRect line I get a runtime error in PAServer window "_setFrameworkScaleFactor called with non-nil _borderView".

I'm guessing I'm doing it wrong but I've found it hard to find any examples.

Ville Krumlinde
  • 7,021
  • 1
  • 33
  • 41
  • Did you look at FMX.Platform.Mac.pas to see how FMX does this? – Giel Jan 31 '14 at 09:24
  • @Giel Yes but it looks like they've overridden NSWindow in a TFMXWindow class. I don't see why that should be necessary and I want to do this without any FMX dependency if possible. – Ville Krumlinde Jan 31 '14 at 09:44
  • 1
    Are you tried [this](http://stackoverflow.com/questions/7442131/delphi-xe2-is-it-possible-to-create-mac-gui-applications-without-firemonkey)? – RRUZ Jan 31 '14 at 12:53
  • @RRUZ Many thanks, that link was the key to getting it working. – Ville Krumlinde Jan 31 '14 at 13:07

1 Answers1

0

Thanks to the comment from RRUZ (in combination with the FMX source like Giel suggested) I managed to get it working:

uses Macapi.AppKit, Macapi.CocoaTypes, Macapi.ObjectiveC;

...

var
  Nw : NSWindow;
begin
  Nw:= TNSWindow.Wrap(TNSWindow.alloc.initWithContentRect(
    MakeNSRect(0,100,100, 100),
    NSTitledWindowMask, NSBackingStoreBuffered, True));

  Nw.orderFront( (TNSApplication.Wrap(TNSApplication.OCClass.sharedApplication) as ILocalObject).GetObjectID );
end;
Ville Krumlinde
  • 7,021
  • 1
  • 33
  • 41