XE4 ( Firemonkey + iOS Static Library) , Pascal conversion from Objective C Class?

前端 未结 1 1710
失恋的感觉
失恋的感觉 2020-12-06 13:48

How to Conversion ? (Objective C Class -> Delphi XE4 )

and How to use Objective-C Class in static Library from Delphi XE ?

Following is the my first trial.

相关标签:
1条回答
  • 2020-12-06 14:20

    When you want to import a Objective C class you have to do the following:

    type
      //here you define the class with it's non static Methods
      objc_test = interface (NSObject)
        [InterfaceGUID]
        function  test(value : integer) : integer; cdecl;     
      end;
    
    type
      //here you define static class Methods 
      objc_testClass = interface(NSObjectClass)
        [InterfaceGUID]
      end;
    
    type
      //the TOCGenericImport maps objC Classes to Delphi Interfaces when you call Create of TObjc_TestClass
      TObjc_TestClass = class(TOCGenericImport<objc_testClass, objc_Test>) end;
    

    Also you need a dlopen('test.a', RTLD_LAZY) (dlopen is defined in Posix.Dlfcn)

    Then you can use the code as following:

    procedure Test;
    var
       testClass: objc_test;
    begin
       testClass := TObjc_TestClass.Create;
       testClass.test(3);
    
    end;
    
    0 讨论(0)
提交回复
热议问题