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

。_饼干妹妹 提交于 2020-01-02 05:14:10

问题


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 rewrite the code with Lars' advice XE4 ( Firemonkey + iOS Static Library) , Pascal conversion from Objective C Class?, Compiling is OK.

But, After running the program in iPad3 device, When press the button, It shows "ObjectiveC class myclac cound not be found"

My Questions are

Q1. Is it right syntax for XE4 & iOS Static Library ?

Q2. with / wihtout Line {$Link libtest.a} Compiled size is same always. What's is wrong in my code ?

Q3. I know iOS App can't use static library except apple library. So, dlOpen is not required. Is it right ?

Always Thanks

Simon, Choi

来源:https://stackoverflow.com/questions/16548367/can-delphi-xe4-import-ios-objc-class-static-library-a

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!