[英]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.