delphi – XE4(Firemonkey iOS静态库),Objective C类的Pascal转
发布时间:2020-12-15 04:34:48 所属栏目:大数据 来源:网络整理
导读:如何转换? (Objective C Class – Delphi XE4) 如何在Delphi XE的静态库中使用Objective-C类? 以下是我的第一次试验. 但它会犯错误. 目标C来源 // objective C : test.h ----------------------------------------@interface objc_test : NSObject { BOOL
|
如何转换? (Objective C Class – > Delphi XE4)
如何在Delphi XE的静态库中使用Objective-C类? 以下是我的第一次试验. 目标C来源 // 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来源 // 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;
谢谢 西蒙,彩 解决方法
如果要导入Objective C类,则必须执行以下操作:
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;
你还需要一个dlopen(‘test.a’,RTLD_LAZY)(dlopen在Posix.Dlfcn中定义) 然后您可以使用以下代码: procedure Test; var testClass: objc_test; begin testClass := TObjc_TestClass.Create; testClass.test(3); end; (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
