Delphi + iOS: how to declare a simple ObjC class?

How can I declare a simple ObjC class in Delphi / Firemonkey (XE5 or XE6)? I want to create an animation delegate class with some delegate methods inside this class.

Thank!

+4
source share
2 answers

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}'] // <-- Press Ctrl+Shift+G to create your own guid - must be unique for every interface
    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; // don't forget this one! The create constructor calls Alloc in inherited
FDelegate := nil;
+4
source

Z ( ) , , , public ( ). , , RTTI , EObjectiveC EObjectiveC "... " .

0

Source: https://habr.com/ru/post/1547952/


All Articles