简体   繁体   English

如何将Objective C @property转换为Delphi XE3

[英]How to convert Objective C @property to Delphi XE3

I'm using Delphi XE3 to develop application for MAC OS X which uses third-party dynamic library (.dylib) for work. 我正在使用Delphi XE3开发用于MAC OS X的应用程序,该应用程序使用第三方动态库(.dylib)进行工作。

Target library has Objective C header file which I'm trying to convert to Delphi. 目标库具有我要转换为Delphi的Objective C头文件。 Almost everything is good, but there is one interface which contains only @property declarations. 几乎一切都很好,但是有一个接口仅包含@property声明。

@interface ProductInitParams : NSObject
{
  NSString* ProductKey;
  NSString* ProductVendor;
  NSString* ProductName;
  NSString* ProductPackage;    
}
@property (nonatomic, retain) NSString* ProductKey;
@property (nonatomic, retain) NSString* ProductVendor;
@property (nonatomic, retain) NSString* ProductName;
@property (nonatomic, retain) NSString* ProductPackage;
@end

I tried to write something like this: 我试图写这样的东西:

ProductInitParams = interface(NSObject)['{149A7187-D3E1-4713-B2D1-6EA1801F4A7D}']
    property ProductKey: NSString read ? write ?;
    property ProductVendor: NSString read ? write ?;
    property ProductName: NSString read ? write ?;
    property ProductPackage: NSString read ? write ?;
end;

but I dont know what to write for read\\write. 但我不知道该为读\\写写什么。

Does anybody know how to do this? 有人知道怎么做这个吗?

PS I looked in Macapi.* units - there is nothing about marshalling properties. PS:我以Macapi。*单位查看-编组属性没有任何关系。

UPDATE 更新

After reading Apple documentation about @property I came up with this solution. 阅读有关@property的Apple 文档后 ,我想到了此解决方案。

ProductInitParams = interface(NSObject)['{149A7187-D3E1-4713-B2D1-6EA1801F4A7D}']
    procedure setProductKey(value: NSString); cdecl;
    procedure setProductVendor(value: NSString); cdecl;
    procedure setProductName(value: NSString); cdecl;
    procedure setProductPackage(value: NSString); cdecl;

    function ProductKey: NSString; cdecl;
    function ProductVendor: NSString; cdecl;
    function ProductName: NSString; cdecl;
    function ProductPackage: NSString; cdecl;

    property ProductKey_: NSString read ProductKey write setProductKey;
    property ProductVendor_: NSString read ProductVendor write setProductVendor;
    property ProductName_: NSString read ProductName write setProductName;
    property ProductPackage_: NSString read ProductPackage write setProductPackage;
end;

I don't know if it is correct solution, but it works. 我不知道这是否是正确的解决方案,但是可以。

If anybody have any comments about possible problems when using this solution, please post. 如果有人对使用此解决方案时可能出现的问题有任何意见,请发表。

In Delphi it should look like this. 在Delphi中,它应该看起来像这样。 Properties are mapped to functions with the name of the property. 属性映射到具有属性名称的函数。 The setter is mapped to a procedure set with the type of the property as parameter. 设置器映射到以属性类型为参数的过程集。

ProductInitParams = interface(NSObject)['{149A7187-D3E1-4713-B2D1-6EA1801F4A7D}']
  function ProductKey : NSString; cdecl;
  procedure setProductKey(value : NSString); cdecl;
  function ProductVendor : NSString; cdecl;
  procedure setProductVendor(value : NSString); cdecl;
end;

Maybe this link also helps you XE4 ( Firemonkey + iOS Static Library) , Pascal conversion from Objective C Class? 也许此链接还可以帮助您从Objective C类进行XE4(Firemonkey + iOS静态库),Pascal转换?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM