Before you can use an Automation object's interface it must be attached to its Automation Server. Sending CreateComObject or AttachActiveObject does this.
This method will launch a new instance of the Automation Server application and attach the Automation controller to it. See also CreateComObject.
This method will search for any current running instances of the Automation Server and attach to it if it finds one. If it does not find one then it does nothing and returns False.
When your DataFlex application has finished with the Automation Server it should be released. This can be done explicitly by sending ReleaseComObject. The Automation Server will be released automatically when the controller object is destroyed.
The example below demonstrates using CreateComObject, AttachActiveObject and ReleaseComObject to connect the simple Automation controller with its server.
Object oAutomationTest is a cComAutoTest
End_Object
Object oConnect_btn is a Button
Set Location to 10 10
Set Label To "Connect"
Procedure OnClick
// Click this button to Attach to the Simple Automation Server
Boolean bIsComObjectCreated
// test If the DataFlex Wrapper is already connected
Get IsComObjectCreated of oAutomationTest To bIsComObjectCreated
If (Not(bIsComObjectCreated)) Begin
// now try to attach to a running instance
Get AttachActiveObject of oAutomationTest To bIsComObjectCreated
If (Not(bIsComObjectCreated)) Begin
// If we got here then we have to create our own instance
Send CreateComObject of oAutomationTest
End
End
End_Procedure // OnClick
End_Object
Object oDisconnect_btn is a Button
Set Location to 10 10
Set Label to "Disconnect"
Procedure OnClick
// Click this button to release the Simple Automation Server
Boolean bIsComObjectCreated
// test If the DataFlex Wrapper is already connected
Get IsComObjectCreated of oAutomationTest To bIsComObjectCreated
If (bIsComObjectCreated) Begin
// now release the automation server
Send ReleaseComObject of oAutomationTest
End
End_Procedure // OnClick
End_Object
Note how the IsComObjectCreated method is used to test whether the Automation controller is connected to an Automation server. This method will return True after AttachActiveObject or CreateComObject have been successfully executed. It will return False after ReleaseComObject has been executed.
Programming with Automation Objects