我在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&二传手术方法。 在我看来,实际上它并不能让你拥有吸气剂和吸气剂。二传手术方法。 因此,我将此转换为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属性的帮助将不胜感激。
答案 0 :(得分:0)
你试过这个:
[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;
我无法测试这个,但你能看看它是否有效吗?
最诚挚的问候,
的Jeroen