簡體   English   中英

Delphi - OSX - 如何擴展 NSWindowDelegate

[英]Delphi - OSX - How to extend NSWindowDelegate

Delphi 中當前的 NSWindowDelegate 實現非常有限。 它不包括諸如windowWillResize:toSize 之類的事件:

我該如何擴展它? 我可以在 source\\rtl\\osx'Macapi.Appkit.pas 中看到代碼,因此我嘗試將該文件的副本復制到我的應用程序文件夾並將其包含在項目中。

但是,在這樣做之后,我得到了很多:

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

擴展它的適當方法是什么? 我怎樣才能擺脫這些錯誤?

您可以創建自己的界面來添加缺少的方法。

  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;

在實現需要這些附加方法的類時,除了Delphi附帶的接口之外,只需添加您的接口。

  TMyWindowDelegate = class(TOCLocal, NSWindowDelegate, NSWindowDelegateEx)
  // ...
  end;

為了擺脫錯誤復制,還要將FMX。[other-unit-name-here]文件復制到項目文件夾中。 它需要重新編譯,因為你已經改變了一些界面。

我嘗試擴展接口,如本主題所示。

我實現了這樣的代碼:

   NSToolbarEx = interface(NSToolbar)
      ['{99470F81-6BDD-4ABF-9B84-DAC9A06595F4}']
      function centeredItemIdentifier: NSString; cdecl;
      procedure setCenteredItemIdentifier(itemIdentifier: NSString); cdecl;
   end;
   TNSToolbarEx = class(TOCGenericImport<NSToolbarClass, NSToolbarEx>)  end;

我在運行時得到這個:

'找不到 ObjectiveC 類 NSToolbarEx'。

如果我實現這樣的代碼:

   NSToolbarEx = interface(NSToolbar)
      ['{99470F81-6BDD-4ABF-9B84-DAC9A06595F4}']
      function centeredItemIdentifier: NSString; cdecl;
      procedure setCenteredItemIdentifier(itemIdentifier: NSString); cdecl;
   end;
   TNSToolbarEx = class(TOCLocal, NSToolbar, NSToolbarEx) end;

我無法編譯,因為它要求從繼承類和基類中實現所有缺失的方法。

編譯器消息

我究竟做錯了什么?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM