XE4(Firemonkey + iOS静态库),Pascal从Objective C类转换? [英] XE4 ( Firemonkey + iOS Static Library) , Pascal conversion from Objective C Class?

查看:258
本文介绍了XE4(Firemonkey + iOS静态库),Pascal从Objective C类转换?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何转换? (Objective C Class - > Delphi XE4)



如何在Delphi XE的静态库中使用Objective-C类?



以下是我的第一次试验。










$ b p> // objective C:test.h ---------------------------------- ------
@interface objc_test:NSObject {
BOOL busy;
}
- (int)test:(int)value;
@end

// objective C:test.m ---------------------------- ------------
@implementation objc_test
- (int)test:(int)value {
busy = true;
return(value + 1);
}
@end

我的转换程式码有误。
如何解决这个问题?



Delphi Source

  // Delphi XE4 / iOS ------------------------------------- ------ 
{$ L test.a} // ObjC静态库

类型
objc_test = interface(NSObject)
function test(value: integer):integer; cdecl;
end;

Tobjc_test = class(TOCLocal)
Public
function GetObjectiveCClass:PTypeInfo;覆盖;
function test(value:integer):integer; cdecl;
end;

implmentation

函数Tobjc_test.GetObjectiveCClass:PTypeInfo;
begin
结果:= TypeInfo(objc_test);
end;

函数Tobjc_test.test(value:integer):integer;
begin
//
//
end;

感谢



Simon,Choi <当你要导入一个Objective C类时,你必须做以下事情:

  type 
//这里你定义类的非静态方法
objc_test = interface(NSObject)
[InterfaceGUID]
function test(value:integer):integer; cdecl;
end;

type
//这里你定义静态类方法
objc_testClass = interface(NSObjectClass)
[InterfaceGUID]
end;

type
//当您调用Create of TObjc_TestClass
TObjc_TestClass = class(TOCGenericImport< objc_testClass,objc_Test>)end时,TOCGenericImport将objC类映射到Delphi接口;另外,你需要一个 dlopen('test.a',RTLD_LAZY)

/ code>(dlopen在Posix.Dlfcn中定义)



然后你可以使用下面的代码:

 程序测试; 
var
testClass:objc_test;
begin
testClass:= TObjc_TestClass.Create;
testClass.test(3);

end;


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. But It makes error.

Objective C Source

// objective C : test.h ----------------------------------------
@interface objc_test : NSObject {
  BOOL busy;
} 
- (int) test :(int) value;
@end

// objective C : test.m ----------------------------------------
@implementation objc_test
- (int) test :(int) value {
    busy   = true;
    return( value + 1);
 }
@end

Here is wrong my conversion code. How to fix that ?

Delphi Source

// Delphi XE4 / iOS  -------------------------------------------
{$L test.a} // ObjC Static Library 

type
 objc_test = interface (NSObject)
 function  test(value : integer) : integer; cdecl;
end;

Tobjc_test = class(TOCLocal)
  Public
   function  GetObjectiveCClass : PTypeInfo; override;
   function  test(value : integer): integer; cdecl; 
end;

implmentation  

function  Tobjc_test.GetObjectiveCClass : PTypeInfo;
 begin
  Result := TypeInfo(objc_test);
 end;

function  Tobjc_test.test(value : integer): integer;
 begin
  // ????????
  //
 end;

Thanks

Simon,Choi

解决方案

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;

这篇关于XE4(Firemonkey + iOS静态库),Pascal从Objective C类转换?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆