Create an interface with your methods and get from IObjectiveC. Also create a guide. I do not post it here, so no one is tempted to use mine.
ISampleDelegate = interface(IObjectiveC)
['{put-your-own-guid-here}']
procedure DispatchItem(Sender: Pointer); cdecl;
end;
Create a delegate implementation and get TOCLocal. It should implement your delegate interface.
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;
Create a delegate:
FDelegate: ISampleDelegate;
FDelegate := TSampleDelegate.Create(Self);
Assign your delegate:
Item.setDelegate(FDelegate);
Free delegate:
Item.setDelegate(nil);
TNSObject.Wrap((FDelegate as ILocalObject).GetObjectID).release;
FDelegate := nil;
source
share