How I can declare a simple ObjC-Class in Delphi/Firemonkey (XE5 or XE6)? I want to create an animation delegate class with some delegate methods inside of this class.
Thanks!
How I can declare a simple ObjC-Class in Delphi/Firemonkey (XE5 or XE6)? I want to create an animation delegate class with some delegate methods inside of this class.
Thanks!
I would like to add to Sebastian Z's answer (but I'm not allowed to comment yet) and just say that the methods in the class that are implementing the delegate interface should be declared as
public
(as Sebastian has done). Either that or make sure the appropriate RTTI information is exposed for the methods, otherwise anEObjectiveC
exception is raised with the message "Method ... not found" when the object is created.Edit: I'm fairly sure that
Item.setDelegate(FDelegate);
in Sebastian Z's answer is wrong and thatGetObjectID
must be used to get the pointer to the delegate object. I was getting Access violations until I made that change.Create an interface with your methods and derive from IObjectiveC. Also create a guid. I'm not posting one here, so that nobody is tempted to use mine.
Create your delegate implementation and derive from TOCLocal. It should implement your delegate interface.
Create the delegate:
Assign your delegate:
Free your delegate: