Next: 2.3.4 Parameter Passing
Up: 2.3 ActiveX binding
Previous: 2.3.2.2 Property Access in
  Contents
The connection points are
part of a standard ActiveX mechanism whose primary objective is to
allow the ActiveX object to notify its owner of any kind of
events. The connection point works as an ``event sink'', where
events and notifications go through.
To establish a connection using LuaCOM, the owner of the ActiveX object
must create a table to implement the connection interface,
whose description is provided by the ActiveX object (this interface
is called a source interface) and then call the API method
Connect
, passing as arguments the LuaCOM object
for the ActiveX object and the implementation table. Doing this,
LuaCOM will automatically find the default source interface, create
a LuaCOM object implemented by the supplied table and then connect
this object to the ActiveX object. Here follows a sample:
-- Creates the ActiveX object
--
calendar = luacom.CreateObject("MSCAL.Calendar")
if calendar == nil then
os.exit(1)
end
-- Creates implementation table
--
calendar_events = {}
function calendar_events:AfterUpdate()
print("Calendar updated!")
end
-- Connects object and table
--
res = luacom.Connect(calendar, calendar_events)
if res == nil then
exit(1)
end
-- This should trigger the AfterUpdate event
--
calendar:NextMonth()
It's also possible to separately create a LuaCOM object implementing the
connection point source interface and then connect it to the object using
AddConnection
.
-- Creates the ActiveX object
--
calendar = luacom.CreateObject("MSCAL.Calendar")
if calendar == nil then
print("Error instantiating calendar")
os.exit(1)
end
-- Creates implementation table
--
calendar_events = {}
function calendar_events:AfterUpdate()
print("Calendar updated!")
end
-- Creates LuaCOM object implemented by calendar_events
--
event_handler = luacom.ImplInterface(calendar_events,
"MSCAL.Calendar",
"DCalendarEvents")
if event_handler == nil then
print("Error implementing DCalendarEvents")
exit(1)
end
-- Connects both objects
--
luacom.addConnection(calendar, event_handler)
-- This should trigger the AfterUpdate event
--
calendar:NextMonth()
-- This disconnects the connection point established
--
luacom.releaseConnection(calendar)
-- This should NOT trigger the AfterUpdate event
--
calendar:NextMonth()
Vinicius da Silva Almendra
2003-06-27