AttachActiveObject - cComAutomationObject

Looks for an active COM object of its class in the system ROT (Running Object Table) and attaches it to the DataFlex object

Type: Function

Return Data Type: Boolean

Parameters: None

Return Value

Returns True if a successful attachment to a running COM object is made, otherwise it returns False.


Syntax
Function AttachActiveObject Returns Boolean

Call: Get AttachActiveObject to BooleanVariable


Description

The AttachActiveObject function looks for an active COM object of its class in the system ROT (Running Object Table). If successful the COM object is attached it to the DataFlex object.

For example when an instance of Word is started, it automatically registers its Application object with the system ROT, so that other Automation Controllers can attach to the same Application object.

You would use this function when you want to ensure that multiple instances of an Automation Controller will attach to only one server.

The below example demonstrates the use of AttachActiveObject to connect to a running instance of MS Word:

Procedure OnClick
    // Click this button to Attach to Word 8 Automation Server.
    Boolean bIsComObjectCreated

    // test If the DataFlex Wrapper is already connected to Word.
    Get IsComObjectCreated of oWordAutomation To bIsComObjectCreated

    If (Not(bIsComObjectCreated)) Begin
        // now try to attach to a running instance of word...
        Get AttachActiveObject of oWordAutomation To bIsComObjectCreated

        If (Not(bIsComObjectCreated)) Begin
            // If we got here then we have to create our own
            // instance of word.
            Send CreateComObject of oWordAutomation
        End
    End
End_Procedure // OnClick

See Also

CreateComObject | ReleaseComObject