【发布时间】:2014-12-04 15:49:41
【问题描述】:
我正在尝试使用 Ruby v1.93 在 COM 对象中设置数组属性。将 COM 中的数组编组到 Ruby 数组中是可行的,但反之则不行。如何将 Ruby 数组编组到 COM 中?
该属性包含在 .NET 程序集中:
namespace LibForRuby
{
public class MyClass
{
public MyClass()
{
MyInt = 1;
MyArray = new[] {2, 3};
}
public int MyInt { get; set; }
public int[] MyArray { get; set; }
}
}
我的整个 ruby 脚本是:
require 'win32ole'
com_class = WIN32OLE.new('LibForRuby.MyClass')
puts 'Before:'
my_int = com_class.MyInt
puts my_int
my_array = com_class.MyArray
print my_array
puts
puts 'After:'
com_class.MyInt = 10
my_int = com_class.MyInt
puts my_int
com_class.MyArray = [20,30]
my_array = com_class.MyArray
print my_array
输出是:
C:\Ruby193\bin>test
Before:
1
[2, 3]
After:
10
C:/Ruby193/bin/test.rb:13:in `method_missing': (in setting property `MyArray': )
(WIN32OLERuntimeError)
OLE error code:0 in <Unknown>
<No Description>
HRESULT error code:0x80020005
Type mismatch.
from C:/Ruby193/bin/test.rb:13:in `<main>'
【问题讨论】: