Domanda

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.

È stato utile?

Soluzione

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;
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top