//用连接点注册事件
//演示用连接点注册事件

import com

calendar = com.CreateObject("MSCAL.Calendar")

calendar_events = {}
calendar_events.AfterUpdate = function() begin
io.print("Calendar updated!")
end

io.print(calendar,calendar_events) 
res, cookie = com.Connect(calendar, calendar_events)

calendar.NextMonth()

 


import com
io.open()

// Instances the COM object
calendar = com.CreateObject("MSCAL.Calendar")
if calendar == null {
print("Error instantiating calendar")
return;
}

// Creates implementation table
calendar_events = {}
function calendar_events.AfterUpdate() begin
io.print("Calendar updated!")
end

// Creates COM object implemented by calendar_events
event_handler = com.ImplInterface(calendar_events,
"MSCAL.Calendar",
"DCalendarEvents")
if event_handler == null {
print("Error implementing DCalendarEvents")
exit(1)
}


// Connects both objects
cookie = com.addConnection(calendar, event_handler)
// This should trigger the AfterUpdate event
io.print(cookie )

calendar.NextMonth()

// This disconnects the connection point established
com.releaseConnection(calendar, event_handler, cookie)

// This should NOT trigger the AfterUpdate event
calendar.NextMonth()
calendar.NextMonth()
calendar.NextMonth()

