在 COM 接口中包含非托管类型属性

Include Unmanaged Type attribute in COM interface

我正在 Oxygene 中为 COM 可调用包装器编写 COM 接口 class。 我不知道如何将 System.Decimal 属性 编组为货币(本机 COM 类型),因为 Oxygene 编译器不允许使用适用于 Delphi.NET.[=12= 的语法]

这是我如何在 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;

(我不会费心去展示各种 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 属性的帮助,我们将不胜感激。

你试过这个吗:

[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;

我没有办法测试这个,但你能看看它是否有效吗?

此致,

杰伦