Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delphi - OSX - How to extend NSWindowDelegate

The current NSWindowDelegate implementation in Delphi is very limited. It doesn't include events such as windowWillResize:toSize:

How can I extend it? I can see the code in source\rtl\osx'Macapi.Appkit.pas so I tried to make a copy of that file to my application folder and include it in the project.

However, after doing that I get lots of:

Unit FMX.[unit-name-here] was compiled with a different version of FMX.[other-unit-name-here].

What would be the appropriate way to extend it? How can I get rid of those errors?

like image 251
Jamie Avatar asked May 26 '15 18:05

Jamie


1 Answers

You can create your own interface that adds the missing methods.

  NSWindowDelegateEx = interface(IObjectiveC)
    [{ Press Ctrl+Shift+G to insert a guid here }]
    procedure windowDidEnterFullScreen(notification: NSNotification); cdecl;
    function window(window: NSWindow; willUseFullScreenContentSize: NSSize): NSSize; cdecl; overload;
    function window(window: NSWindow; willUseFullScreenPresentationOptions: NSApplicationPresentationOptions): NSApplicationPresentationOptions; cdecl; overload;
  end;

When implementing the class that needs these additional methods, simply add your interface in addition to the interface that comes with Delphi.

  TMyWindowDelegate = class(TOCLocal, NSWindowDelegate, NSWindowDelegateEx)
  // ...
  end;
like image 93
Sebastian Z Avatar answered Oct 20 '22 03:10

Sebastian Z