Ruby v1.93을 사용하여 COM 객체에서 배열 속성을 설정하려고합니다. COM에서 Ruby 배열로 배열을 정렬하는 것은 작동하지만 다른 방향으로는 작동하지 않습니다. 어떻게하면 Ruby 배열을 COM으로 정렬 할 수 있습니까?Ruby 및 Win32OLE을 사용하여 배열 설정
속성은 .NET 어셈블리에 포함되어 있습니다 :
namespace LibForRuby
{
public class MyClass
{
public MyClass()
{
MyInt = 1;
MyArray = new[] {2, 3};
}
public int MyInt { get; set; }
public int[] MyArray { get; set; }
}
}
내 전체 루비 스크립트입니다 :
는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>'
흠 ... 새로운 코드가 이미 노력하고 코드의 라인 앞에는 그는 내가 그 포스트에서 보여준 오류이다. 그 줄을 생략하기로했다면, 그 줄을 사용하지 않고 실행 해 보았지만 setproperty에 대한 호출은 다음과 같이 실패합니다 : 'ole_method': MyArray가 없습니다. –
사실, print com_class.ole_get_methods는 나에게 []을줍니다. –
죄송합니다. 실패한 행을 삭제하려고했습니다. 불쌍한 복사/붙여 넣기 작업. 이 (편집 된) 코드를 아직 실행 해 보셨습니까? 결과 및/또는 오류가 무엇입니까? –