COMARRAY( ) Function

Specifies how to pass arrays to COM objects.

COMARRAY(oObject [, nNewValue])

Parameters

  • oObject
    Specifies an object reference to a COM object.

  • nNewValue
    Specifies how to pass an array to a COM object specified with oObject.

    The following table lists the settings for nNewValue and how the to pass the array to the COM object.

    nNewValue

    Description

    0

    The array is a zero-based array and is passed by value.

    1

    The array is a one-based array and is passed by value. Compatible with earlier versions of Visual FoxPro. (Default)

    10

    The array is a zero-based array and is passed by reference.

    11

    The array is a one-based array and is passed by reference.

    100

    The array is a fixed size array and cannot be redimensioned.

    1000

    Byte arrays are not converted to strings.

    To return the current setting, call COMARRAY( ) without an argument for the nNewValue parameter.

Return Value

Numeric. COMARRAY( ) returns the current setting.

Remarks

Use COMARRAY( ) only when you pass arrays to COM objects using the following syntax:

oComObject.Method(@MyArray)

Note

If you omit the at sign (@), only the first element of the array passes to the COM object, and COMARRAY( ) has no effect. This behavior is the same as that in earlier versions of Visual FoxPro.

When you use a byte array (VT_UI1) to communicate with a COM server, Visual FoxPro converts the byte array into a string. The additive nValue of 1000 retains the original proper type of the array and does not convert the result to a string.

If a client passes a byte array by reference to a Visual FoxPro COM Server, the Visual FoxPro COM Server must also set the nValue additive to 1000. You can do this by putting the following call in the Init event of the Visual FoxPro COM Server:

COMARRAY(THIS,1000)

The additive nValue of 100 makes it possible for you to prevent redimensioning of an array. You should check for possible errors after calling the server in case the server attempts to redimension the array. The following example shows how to prevent redimensioning of the array. To run this example, first build the class definition into a DLL named "t1.dll".

LOCAL loSvr, laTest
loSvr = NEWOBJECT("t1.arrayhandler")
DIMENSION laTest[10]
laTest=3
? COMARRAY(loSvr,11 + 100)
* The COM server will return an error on the next line of code
* because arrays passed to loSvr will not allow re-dimensioning.
loSvr.RedimensionArray(@laTest,4)
? ALEN(laTest)

DEFINE CLASS ARRAYHANDLER AS CUSTOM OLEPUBLIC
    PROCEDURE RedimensionArray(aArray, nRows)
        DIME aArray[nRows]
    ENDPROC
ENDDEFINE

See Also

Reference

Passing Arrays to Automation Servers

COMCLASSINFO( ) Function

CREATEOBJECT( ) Function

GETOBJECT( ) Function

Other Resources

Functions

Language Reference (Visual FoxPro)