Programming Guide:xppguide

Reacting to COM/ActiveX events Foundation

Similar to the callback slots provided by the Xbase Parts, COM/ActiveX components often use events to communicate with the user of the COM/ActiveX component. The additional functionality required to react to COM/ActiveX events is provided by the class ActiveXObject(), which is derived from class AutomationObject().

To react to a COM/ActiveX event, the Xbase++ application needs to supply a code block which is evaluated when the event is fired. The code block must be assigned to a callback slot that has the same name as the COM/ActiveX event.

Alternately, a callback method for processing the COM/ActiveX method can be defined in a class derived from class ActiveXObject. The callback method must have the same name as the associated COM/ActiveX event. It is called automatically whenever the COM/ActiveX event is fired.

Creating objects of class ActiveXObject

Instances of class ActiveXObject can be created in one of two ways. To create an object from scratch, use the class method :create(). To use an object which has been previously created (via the functions CreateObject() or GetObject()), a cast to an object of a dedicated class ActiveXObject must be created. For this, the method :dynamicCast() is provided. This method accepts the name or class object of the target class as a parameter.

#pragma library( "ascom10.lib" ) 
PROCEDURE MAIN 
LOCAL oWord, cMsg 

oWord := GetObject( NIL, "Word.Application" ) 
IF NIL == oWord 
   ? "Error" 
   ? ComLastError() 
   ? ComLastMessage() 
ENDIF 

oWord:visible := .T. 

// 
// Cast AutomationObject to instance of class 
// ActiveXObject. This is a prerequisite for 
// being able to react to COM/ActiveX events 
// 
oWord := oWord:dynamicCast( "ActiveXObject" ) 

// 
// Assign a code block to the callback slot of 
// the "quit" COM/ActiveX event 
// 
oWord:quit := { || MsgBox("Word sent quit event") } 

cMsg := "Close Word to see the message box. " 
cMsg += "Push button to continue" 

WAIT cMsg 

RETURN 

Feedback

If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.