本文簡要介紹ruby語言中 WIN32OLE_EVENT#on_event 的用法。
用法
WIN32OLE_EVENT#on_event([event]){...}
定義回調事件。如果省略參數,則此方法定義所有事件的回調。如果要修改回調中的引用參數,請在回調中返回哈希。如果您想將值作為回調的結果返回給 OLE 服務器,請使用 ‘return’ 或:return。
ie = WIN32OLE.new('InternetExplorer.Application')
ev = WIN32OLE_EVENT.new(ie)
ev.on_event("NavigateComplete") {|url| puts url}
ev.on_event() {|ev, *args| puts "#{ev} fired"}
ev.on_event("BeforeNavigate2") {|*args|
...
# set true to BeforeNavigate reference argument `Cancel'.
# Cancel is 7-th argument of BeforeNavigate,
# so you can use 6 as key of hash instead of 'Cancel'.
# The argument is counted from 0.
# The hash key of 0 means first argument.)
{:Cancel => true} # or {'Cancel' => true} or {6 => true}
}
ev.on_event(...) {|*args|
{:return => 1, :xxx => yyy}
}
相關用法
- Ruby WIN32OLE_EVENT#on_event_with_outargs用法及代碼示例
- Ruby WIN32OLE_EVENT#off_event用法及代碼示例
- Ruby WIN32OLE_EVENT#handler=用法及代碼示例
- Ruby WIN32OLE_EVENT#unadvise用法及代碼示例
- Ruby WIN32OLE_EVENT.new用法及代碼示例
- Ruby WIN32OLE_METHOD#visible?用法及代碼示例
- Ruby WIN32OLE_TYPE#src_type用法及代碼示例
- Ruby WIN32OLE_VARIANT[i,j,...] =用法及代碼示例
- Ruby WIN32OLE_PARAM#ole_type_detail用法及代碼示例
- Ruby WIN32OLE_RECORD類用法及代碼示例
- Ruby WIN32OLE_VARIANT[i,j,...]用法及代碼示例
- Ruby WIN32OLE_RECORD#to_h用法及代碼示例
- Ruby WIN32OLE_RECORD#ole_instance_variable_get用法及代碼示例
- Ruby WIN32OLE_TYPE#typekind用法及代碼示例
- Ruby WIN32OLE_VARIANT.vartype用法及代碼示例
- Ruby WIN32OLE_TYPE#source_ole_types用法及代碼示例
- Ruby WIN32OLE_VARIABLE#name用法及代碼示例
- Ruby WIN32OLE_PARAM#retval?用法及代碼示例
- Ruby WIN32OLE_PARAM#input?用法及代碼示例
- Ruby WIN32OLE_TYPE#default_event_sources用法及代碼示例
- Ruby WIN32OLE_TYPE#helpcontext用法及代碼示例
- Ruby WIN32OLE_RECORD#inspect用法及代碼示例
- Ruby WIN32OLE_METHOD#helpstring用法及代碼示例
- Ruby WIN32OLE_METHOD#event_interface用法及代碼示例
- Ruby WIN32OLE_METHOD#invkind用法及代碼示例
注:本文由純淨天空篩選整理自ruby-lang.org大神的英文原創作品 WIN32OLE_EVENT#on_event。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
