2014-07-10 54 views

回答

3

用你的方法創建一個接口並從IObjectiveC派生。也創建一個GUID。我沒有在這裏發佈,所以沒有人試圖使用我的。

ISampleDelegate = interface(IObjectiveC) 
    ['{put-your-own-guid-here}'] // <-- Press Ctrl+Shift+G to create your own guid - must be unique for every interface 
    procedure DispatchItem(Sender: Pointer); cdecl; 
    end; 

創建您的委託實現並從TOCLocal派生。它應該實現你的委託接口。

TSampleDelegate = class(TOCLocal, ISampleDelegate) 
    private 
    FOwner: TMenuItem; 
    public 
    constructor Create(AOwner: TMenuItem); 
    procedure DispatchItem(Sender: Pointer); cdecl; 
    end; 

constructor TSampleDelegate.Create(AOwner: TMenuItem); 
begin 
    inherited Create; 
    FOwner := AOwner; 
end; 

創建委託:

FDelegate: ISampleDelegate; 

FDelegate := TSampleDelegate.Create(Self); 

將您的委託:

Item.setDelegate(FDelegate); 

免費的委託:

Item.setDelegate(nil); 
TNSObject.Wrap((FDelegate as ILocalObject).GetObjectID).release; // don't forget this one! The create constructor calls Alloc in inherited 
FDelegate := nil;