Method AutomationObject():dynamicCast() Foundation

Converts (casts) an AutomationObject instance to another class.

Syntax
:dynamicCast( <xClass> ) --> o
Parameters
<xClass>
Parameter <xClass> specifies the class the object (self) should be cast to. The class may be specified by passing either a character string with the class' name or by using the return of the class' class function, eg. ActiveXObject().
Return

This method returns the object cast to the automation class specified.

Description

The class AutomationObject is the generic base class for all automation and ActiveX objects. Instances of the AutomationObject class are used to connect to a COM/ActiveX component in order to access its methods and properties. Likewise, of a COM object is returned as the result of a method call, it is returned as an object of the AutomationObject class.

When working with COM/ActiveX components, an application often uses subclasses of the AutomationObject class to communicate with the COM/ActiveX component. If the application needs to respond to COM events, for example, an object of class ActiveXObject is required. Likewise, writing wrapper classes for COM/ActiveX objects often involves exposing specialized methods or instance variables. This introduces the requirement to cast an AutomationObject to an instance of another automation class. For this, the method :dynamicCast() can be used.

The method :dynamicCast() creates an instance of the class passed in parameter <xClass> and connects it to the COM/ActiveX object.

After an AutomationObject was cast to another class, it can no longer be used to communicate with the COM/ActiveX component it was connected to!

// 
// Example for using :dynamicCast() to react to an 
// event exposed by a COM object created via :CreateObject() 
// 
#PRAGMA LIBRARY("ASCOM10.LIB") 

PROCEDURE Main() 

 LOCAL oObj 

   // Cast an AutomationObject to an instance of the ActiveXObject class 
   oObj := CreateObject( "Word.Application" ) 
   oObj := oObj:dynamicCast( ActiveXObject() ) 
   oObj:visible := .T. 

   oObj:quit := {|| MsgBox("Word Application has closed!")} 

   WAIT 
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.