我正在用Oxygene为COM可调用的包装类编写COM接口。我不知道如何将System.Decimal属性作为货币(原生COM类型)来传递,因为Oxygene编译器不允许使用Delphi.NET的语法。
下面是我如何在Delphi.NET中成功地做到这一点的一个简单的例子
[ComVisible(True)]
IVarious = interface(IInterface)
['{2DBF9ACD-1574-4BE4-812A-5D0B8E9AA025}']
function get_MyString: String;
procedure set_MyString(strValue: String);
[return: MarshalAs(UnmanagedType.Currency)]
function get_MyAmount: System.Decimal;
procedure set_MyAmount([MarshalAs(UnmanagedType.Currency)] curValue: System.Decimal);
property MyString: String read get_MyString write set_MyString;
property MyAmount: System.Decimal read get_MyAmount write set_MyAmount;
end;
// In Delphi.NET the implementing class only needed to have the methods, not the properties
[ComVisible(False)]
[ClassInterface(ClassInterfaceType.None)]
TVarious = class(TObject, Various)
private
FMyString: string;
FMyAmount: System.Decimal;
public
function get_MyString: String;
procedure set_MyString(strValue: String);
[return: MarshalAs(UnmanagedType.Currency)]
function get_MyAmount: System.Decimal;
procedure set_MyAmount([MarshalAs(UnmanagedType.Currency)] curValue: System.Decimal);
end;(我不想展示TVarious、getter和setter方法实现,因为它们非常明显。)
我知道Oxygene不需要接口来声明getter & setter方法。在我看来,它实际上不允许您有getter & setter方法。所以,我能把它转换成Oxygene (到目前为止)的唯一方法是:
[ComVisible(True)]
[Guid('2DBF9ACD-1574-4BE4-812A-5D0B8E9AA025')]
IVarious = interface
property MyString: String read write;
property MyAmount: System.Decimal read write;
end;
[ComVisible(False)]
[ClassInterface(ClassInterfaceType.None)]
TVarious = class(IVarious)
public
property MyString: String;
property MyCurrency: System.Decimal;
end;但我的问题是,我还没有弄清楚如何将MarshalAs(UnmanagedType.Currency)属性包含到这些声明中。
有关如何在接口中包含此COM属性的帮助将不胜感激。
发布于 2015-03-02 09:25:04
你试过这个吗?
[ComVisible(True)]
[Guid('2DBF9ACD-1574-4BE4-812A-5D0B8E9AA025')]
IVarious = interface
property MyString: String read write;
property MyAmount: System.Decimal read write;
end;
[ComVisible(False)]
[ClassInterface(ClassInterfaceType.None)]
TVarious = class(IVarious)
public
property MyString: String;
[var: MarshalAs(UnmanagedType.Currency)]
property MyAmount: System.Decimal;
end;我没有办法测试这个,但你能看看它是否有效吗?
诚挚的问候,
耶伦
https://stackoverflow.com/questions/28782595
复制相似问题