Skip to content

Attaching to the Automation Server

Before you can use an Automation object's interface, it must be attached to its Automation Server. Sending CreateComObject or AttachActiveObject does this.

CreateComObject

This method will launch a new instance of the Automation Server application and attach the Automation controller to it. See also CreateComObject.

AttachActiveObject

This method will search for any currently 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.

ReleaseComObject

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.

See Also