oxygene

Include Unmanaged Type attribute in COM interface


I'm writing COM interfaces in Oxygene for a COM callable wrapper class. I can't figure out how to marshall a System.Decimal property as currency (native COM type) since the Oxygene compiler won't allow the syntax that worked for Delphi.NET.

Here's a chopped down example of how I did it succesfully in 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;

(I won't bother to show the TVarious getter and setter method implementations since they're pretty obvious.)

I understand that Oxygene doesn't require interfaces to declare getter & setter methods. It seems to me that in fact it doesn't allow you to have getter & setter methods. So, the only way I can convert this to Oxygene (so far) is:

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

But my problem is that I have not been able to figure out how to include the [MarshalAs(UnmanagedType.Currency)] attribute into either of these declarations.

Help on how to include this COM attribute in the interface would be appreciated.


Solution

  • Did you try this:

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

    I have no way to test this, but can you see if it works?

    Best Regards,

    Jeroen