Can Delphi XE4 import iOS ObjC Class? (Static library * .a)

Can Delphi XE4 import iOS ObjC Class? (Static library * .a)

ObjC Code: test.a

// test.h --------------------------------------------------------------- #import <Foundation/Foundation.h> @interface mycalc : NSObject { BOOL busy; } - (int) calc : (int) value; @end // test.m -------------------------------------------------------------- #import "test.h" @implementation mycalc -(int) calc:(int)value { busy = TRUE; return ( value + 1); } @end 

Delphi XE4 code "Unit1.pas" for testing

 Unit1; interface uses System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,System.TypInfo, FMX.Types, FMX.Controls, FMX.Forms, FMX.Dialogs, FMX.StdCtrls, // Posix.Dlfcn, Macapi.ObjectiveC,Macapi.ObjCRuntime, iOSapi.CocoaTypes,iOSapi.foundation,iOSapi.uikit,iOSapi.CoreGraphics; {$Link libtest.a} // <-- ObjC Static Library (3 Architectures included) // But Compiled binary size is always same, // with or without "$Link libtest.a" lines. type // mycalc = interface(NSObject) ['{12891142-0F45-410D-A9EF-212F1AE23294}'] // Any Unique GUID function test(value : integer) : integer; cdecl; end; mycalcclass = interface(NSObjectClass) ['{42891142-0F45-410D-A9EF-212F1AE23295}'] // Any Unique GUID end; //the TOCGenericImport maps objC Classes to Delphi Interfaces // when you call Create of TObjc_TestClass TmycalcClass = class(TOCGenericImport<mycalcclass, mycalc>) end; // ------------------------------------------------------------------------- TForm1 = class(TForm) Button1: TButton; procedure Button1Click(Sender: TObject); private public end; var Form1: TForm1; implementation {$R *.fmx} procedure TForm1.Button1Click(Sender: TObject); Var occalc : mycalc; rtn : integer; handle : integer; begin handle := dlOpen('libtest.a',RTLD_LAZY); // ## Q2 : Is It Right ? occalc := TmycalcClass.Create; // ## Q3 : Error : // Can't found ObjC Class mycalc rtn := occalc.test(100); Button1.Text := 'rst:' + IntToStr(rtn); end; end. 

I am rewriting code using the Lars XE4 board (Firemonkey + iOS static library), Pascal conversion from Objective-C class , Compilation is fine.

But, after starting the program in the iPad3 device, click the button. It shows "ObjectiveC class myclac class not found"

My questions

Q1. Is the syntax correct for the XE4 static library and iOS?

Q2. c / wihtout Line {$ Link libtest.a} The compiled size is always the same. What is wrong in my code?

Q3. I know that an iOS application cannot use a static library other than the Apple library. Therefore, dlOpen is not required. Right?

Always thanks

Simon Choi

+4
source share

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


All Articles