Microsoft KB Archive/221720

= FIX: COM Servers Cannot Redimension Arrays Passed By Reference =

Article ID: 221720

Article Last Modified on 10/16/2002

-

APPLIES TO


 * Microsoft Visual FoxPro 5.0 Standard Edition
 * Microsoft Visual FoxPro 5.0a
 * Microsoft Visual FoxPro 6.0 Professional Edition

-



This article was previously published under Q221720



SYMPTOMS
You pass an array by reference to a method of a COM server built in Visual FoxPro. The method redimensions the array. If you call the method from a Visual FoxPro 6.0 client and use the COMARRAY function, you may see the following error:

OLE IDispatch exception code 302 from Visual FoxPro for Windows: Data type mismatch...

If you call the method from a Visual FoxPro 5.0 client, or a Visual FoxPro 6.0 client not using the COMARRAY function, you may not see an error, but instead the array will not be redimensioned, and the array's original contents remain unchanged. From clients other than Visual FoxPro, you may see the earlier behaviors, or other variations.



STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.

This bug has been fixed in Visual Studio 6.0 Service Pack 3.



Steps to Reproduce Behavior
 Create a new project called Arraytest. Add a new program to the project.  Paste the following code into the program: DEFINE CLASS arraydim AS CUSTOM OLEPUBLIC cVerStr = VERSION PROCEDURE GetArray(taArray, tnRows) IF PARAMETERS < 2 tnRows = ALEN(taArray) ENDIF LOCAL lni DIMENSION taArray[tnRows] FOR lni = 1 TO ALEN(taArray) taArray[lni] = lni ENDFOR RETURN ENDPROC ENDDEFINE  Save the program as Arraytest.prg. Build the project into a COM DLL.  Run the following code from a program (.prg) file: CLEAR CLEAR ALL LOCAL ARRAY laArray[5] LOCAL OX  ox = CREATEOBJECT('arraytest.arraydim') * =COMARRAY(ox,11) STORE 'X' to laArray ?'Value of first element',laArray[1] ?'Array length before', ALEN(laArray) ox.GetArray(@laArray, 10) RELEASE ox  ?'Array length after', ALEN(laArray) ?'Value of first element',laArray[1] </li> From a Visual FoxPro 5.0 client (this must be done with the COMARRAY function removed) the array length and value of the first element are unchanged. From a Visual FoxPro 6.0 client, using the COMARRAY function, the error listed in SYMPTOMS will occur. From a Visual FoxPro 6.0 client not using the COMARRAY function, the behavior is the same as that under Visual FoxPro 5.0.</li></ol>

<div class="references_section">