0
votes

I'm using Delphi XE3 to develop application for MAC OS X which uses third-party dynamic library (.dylib) for work.

Target library has Objective C header file which I'm trying to convert to Delphi. Almost everything is good, but there is one interface which contains only @property declarations.

@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?

P.S. I looked in Macapi.* units - there is nothing about marshalling properties.

UPDATE

After reading Apple documentation about @property I came up with this solution.

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.

1

1 Answers

1
votes

In Delphi it should look like this. 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?