class WIN32OLE::Param

WIN32OLE::Param 对象表示 OLE 方法的参数信息。

公共类方法

new(method, n) → WIN32OLE::Param 对象 点击以切换源代码

返回 WIN32OLE::Param 对象,该对象表示 OLE 参数信息。 第一个参数应为 WIN32OLE::Method 对象。 第二个参数 'n' 是由第一个参数指定的方法的第 n 个参数。

tobj = WIN32OLE::Type.new('Microsoft Scripting Runtime', 'IFileSystem')
method = WIN32OLE::Method.new(tobj, 'CreateTextFile')
param = WIN32OLE::Param.new(method, 2) # => #<WIN32OLE::Param:Overwrite=true>
static VALUE
foleparam_initialize(VALUE self, VALUE olemethod, VALUE n)
{
    int idx;
    if (!rb_obj_is_kind_of(olemethod, cWIN32OLE_METHOD)) {
        rb_raise(rb_eTypeError, "1st parameter must be WIN32OLE::Method object");
    }
    idx = RB_FIX2INT(n);
    return oleparam_ole_param(self, olemethod, idx);
}

公共实例方法

default 点击以切换源代码

返回默认值。如果默认值不存在,则此方法返回 nil。

tobj = WIN32OLE::Type.new('Microsoft Excel 9.0 Object Library', 'Workbook')
method = WIN32OLE::Method.new(tobj, 'SaveAs')
method.params.each do |param|
  if param.default
    puts "#{param.name} (= #{param.default})"
  else
    puts "#{param}"
  end
end

以上脚本的结果如下

Filename
FileFormat
Password
WriteResPassword
ReadOnlyRecommended
CreateBackup
AccessMode (= 1)
ConflictResolution
AddToMru
TextCodepage
TextVisualLayout
static VALUE
foleparam_default(VALUE self)
{
    struct oleparamdata *pparam;
    TypedData_Get_Struct(self, struct oleparamdata, &oleparam_datatype, pparam);
    return ole_param_default(pparam->pTypeInfo, pparam->method_index,
                             pparam->index);
}
input? 点击以切换源代码

如果参数是输入,则返回 true。

tobj = WIN32OLE::Type.new('Microsoft Excel 9.0 Object Library', 'Workbook')
method = WIN32OLE::Method.new(tobj, 'SaveAs')
param1 = method.params[0]
puts param1.input? # => true
static VALUE
foleparam_input(VALUE self)
{
    struct oleparamdata *pparam;
    TypedData_Get_Struct(self, struct oleparamdata, &oleparam_datatype, pparam);
    return ole_param_flag_mask(pparam->pTypeInfo, pparam->method_index,
                               pparam->index, PARAMFLAG_FIN);
}
inspect → String 点击以切换源代码

返回带有类名称的参数名称。如果参数具有默认值,则返回带有类名称的 name=value 字符串。

static VALUE
foleparam_inspect(VALUE self)
{
    VALUE detail = foleparam_name(self);
    VALUE defval = foleparam_default(self);
    if (defval != Qnil) {
        rb_str_cat2(detail, "=");
        rb_str_concat(detail, rb_inspect(defval));
    }
    return make_inspect("WIN32OLE::Param", detail);
}
name 点击以切换源代码

返回名称。

tobj = WIN32OLE::Type.new('Microsoft Excel 9.0 Object Library', 'Workbook')
method = WIN32OLE::Method.new(tobj, 'SaveAs')
param1 = method.params[0]
puts param1.name # => Filename
static VALUE
foleparam_name(VALUE self)
{
    return rb_ivar_get(self, rb_intern("name"));
}
也别名为: to_s
ole_type 点击以切换源代码

返回 WIN32OLE::Param 对象(OLE 方法的参数)的 OLE 类型。

tobj = WIN32OLE::Type.new('Microsoft Excel 9.0 Object Library', 'Workbook')
method = WIN32OLE::Method.new(tobj, 'SaveAs')
param1 = method.params[0]
puts param1.ole_type # => VARIANT
static VALUE
foleparam_ole_type(VALUE self)
{
    struct oleparamdata *pparam;
    TypedData_Get_Struct(self, struct oleparamdata, &oleparam_datatype, pparam);
    return ole_param_ole_type(pparam->pTypeInfo, pparam->method_index,
                              pparam->index);
}
ole_type_detail 点击以切换源代码

返回参数类型的详细信息。

tobj = WIN32OLE::Type.new('Microsoft Excel 9.0 Object Library', 'IWorksheetFunction')
method = WIN32OLE::Method.new(tobj, 'SumIf')
param1 = method.params[0]
p param1.ole_type_detail # => ["PTR", "USERDEFINED", "Range"]
static VALUE
foleparam_ole_type_detail(VALUE self)
{
    struct oleparamdata *pparam;
    TypedData_Get_Struct(self, struct oleparamdata, &oleparam_datatype, pparam);
    return ole_param_ole_type_detail(pparam->pTypeInfo, pparam->method_index,
                                     pparam->index);
}
optional? 点击以切换源代码

如果参数是可选的,则返回 true。

tobj = WIN32OLE::Type.new('Microsoft Excel 9.0 Object Library', 'Workbook')
method = WIN32OLE::Method.new(tobj, 'SaveAs')
param1 = method.params[0]
puts "#{param1.name} #{param1.optional?}" # => Filename true
static VALUE
foleparam_optional(VALUE self)
{
    struct oleparamdata *pparam;
    TypedData_Get_Struct(self, struct oleparamdata, &oleparam_datatype, pparam);
    return ole_param_flag_mask(pparam->pTypeInfo, pparam->method_index,
                               pparam->index, PARAMFLAG_FOPT);
}
output? 点击以切换源代码

如果参数是输出,则返回 true。

tobj = WIN32OLE::Type.new('Microsoft Internet Controls', 'DWebBrowserEvents')
method = WIN32OLE::Method.new(tobj, 'NewWindow')
method.params.each do |param|
  puts "#{param.name} #{param.output?}"
end

以上脚本的结果如下

URL false
Flags false
TargetFrameName false
PostData false
Headers false
Processed true
static VALUE
foleparam_output(VALUE self)
{
    struct oleparamdata *pparam;
    TypedData_Get_Struct(self, struct oleparamdata, &oleparam_datatype, pparam);
    return ole_param_flag_mask(pparam->pTypeInfo, pparam->method_index,
                               pparam->index, PARAMFLAG_FOUT);
}
retval? 点击以切换源代码

如果参数是返回值,则返回 true。

tobj = WIN32OLE::Type.new('DirectX 7 for Visual Basic Type Library',
                          'DirectPlayLobbyConnection')
method = WIN32OLE::Method.new(tobj, 'GetPlayerShortName')
param = method.params[0]
puts "#{param.name} #{param.retval?}"  # => name true
static VALUE
foleparam_retval(VALUE self)
{
    struct oleparamdata *pparam;
    TypedData_Get_Struct(self, struct oleparamdata, &oleparam_datatype, pparam);
    return ole_param_flag_mask(pparam->pTypeInfo, pparam->method_index,
                               pparam->index, PARAMFLAG_FRETVAL);
}
to_s()

返回名称。

tobj = WIN32OLE::Type.new('Microsoft Excel 9.0 Object Library', 'Workbook')
method = WIN32OLE::Method.new(tobj, 'SaveAs')
param1 = method.params[0]
puts param1.name # => Filename
别名为: name