在delphi中,我有这个程序:
procedure addObserver(observer: NSObject; ...)
观察者必须实现键值观察方法observeValue()
,所以我试着这样做:
IKVODelegate = interface(IObjectiveC)
['{B8C6720A-79B7-4FD6-B9E3-77594E905B3C}']
procedure observeValueForKeyPath(keyPath: NSString; ofObject: Pointer; change: NSDictionary; context: Pointer); cdecl;
end;
TKVODelegate = class(TOCLocal, IKVODelegate)
private
public
procedure observeValueForKeyPath(keyPath: NSString; ofObject: Pointer; change: NSDictionary; context: Pointer); cdecl;
end;
然而,问题是TKVODelegate
不是NSObject
后代,因此我无法执行以下操作:
addObserver(MyKVODelegate)
这是因为addObserver
正在等待NSobject
。我怎么能做到这一点?