Microsoft KB Archive/171438: Difference between revisions

From BetaArchive Wiki
(importing KB archive)
 
m (Text replacement - """ to """)
 
Line 67: Line 67:
<li><p>Place the following code in a program file and add the program file to a project named OLETest. Compile the project into an OLE DLL or EXE named OLETest.</p>
<li><p>Place the following code in a program file and add the program file to a project named OLETest. Compile the project into an OLE DLL or EXE named OLETest.</p>
<pre class="codesample">      DEFINE CLASS ARRAYTEST AS CUSTOM OLEPUBLIC
<pre class="codesample">      DEFINE CLASS ARRAYTEST AS CUSTOM OLEPUBLIC
       NAME = &quot;arraytest&quot;
       NAME = "arraytest"


       PROCEDURE DOIT
       PROCEDURE DOIT
Line 74: Line 74:
         INSERT INTO foot (ONE,TWO,THREE,FOUR) VALUES ;
         INSERT INTO foot (ONE,TWO,THREE,FOUR) VALUES ;
             (MYARRAY[1],MYARRAY[2],MYARRAY[3],MYARRAY[4])
             (MYARRAY[1],MYARRAY[2],MYARRAY[3],MYARRAY[4])
         MYARRAY [1] = &quot;100&quot;
         MYARRAY [1] = "100"
         MYARRAY [2] = &quot;200&quot;
         MYARRAY [2] = "200"
         MYARRAY [3] = &quot;300&quot;
         MYARRAY [3] = "300"
         MYARRAY [4] = &quot;400&quot;
         MYARRAY [4] = "400"


         USE CURDIR() + &quot;foot.dbf&quot;
         USE CURDIR() + "foot.dbf"
         INSERT INTO foot (ONE,TWO,THREE,FOUR) VALUES ;
         INSERT INTO foot (ONE,TWO,THREE,FOUR) VALUES ;
             (MYARRAY[1],MYARRAY[2],MYARRAY[3],MYARRAY[4])
             (MYARRAY[1],MYARRAY[2],MYARRAY[3],MYARRAY[4])
Line 96: Line 96:
       CLEAR ALL
       CLEAR ALL
       DIMENSION MYARRAY[4]
       DIMENSION MYARRAY[4]
       MYARRAY(1) = &quot;1&quot;
       MYARRAY(1) = "1"
       MYARRAY(2) = &quot;2&quot;
       MYARRAY(2) = "2"
       MYARRAY(3) = &quot;3&quot;
       MYARRAY(3) = "3"
       MYARRAY(4) = &quot;4&quot;
       MYARRAY(4) = "4"
       OX = CREATEOBJECT(&quot;OLEtest.arraytest&quot;)
       OX = CREATEOBJECT("OLEtest.arraytest")
       OX.DOIT(@MYARRAY)
       OX.DOIT(@MYARRAY)
       ?OX.Name
       ?OX.Name
       ?&quot;MyArray from Calling Program&quot;
       ?"MyArray from Calling Program"
       DISPLAY MEMORY LIKE MYARRAY
       DISPLAY MEMORY LIKE MYARRAY
       RELEASE OX
       RELEASE OX
Line 110: Line 110:
       BROWSE NOWAIT
       BROWSE NOWAIT
                     </pre></li>
                     </pre></li>
<li>Notice the first record of table &quot;foot&quot; contains the values placed in the array by the calling program. The second record contains the values PROCEDURE DOIT placed in the array. The DISPLAY MEMORY LIKE MYARRAY command, however, contains the original values of the array. Even though it appears that we are passing the array by reference to the OLE object, Microsoft Visual FoxPro is passing it by value.</li></ol>
<li>Notice the first record of table "foot" contains the values placed in the array by the calling program. The second record contains the values PROCEDURE DOIT placed in the array. The DISPLAY MEMORY LIKE MYARRAY command, however, contains the original values of the array. Even though it appears that we are passing the array by reference to the OLE object, Microsoft Visual FoxPro is passing it by value.</li></ol>





Latest revision as of 11:05, 21 July 2020

Knowledge Base


Article ID: 171438

Article Last Modified on 5/12/2003



APPLIES TO

  • Microsoft Visual FoxPro 3.0 Standard Edition
  • Microsoft Visual FoxPro 3.0b Standard Edition
  • Microsoft Visual FoxPro 5.0 Standard Edition
  • Microsoft Visual FoxPro 5.0a
  • Microsoft Visual FoxPro 3.0b for Macintosh



This article was previously published under Q171438

SYMPTOMS

Microsoft Visual FoxPro does not support passing arrays by reference to OLE objects.

STATUS

This behavior is by design.

MORE INFORMATION

Steps to Reproduce Behavior

  1. Place the following code in a program file and add the program file to a project named OLETest. Compile the project into an OLE DLL or EXE named OLETest.

          DEFINE CLASS ARRAYTEST AS CUSTOM OLEPUBLIC
          NAME = "arraytest"
    
          PROCEDURE DOIT
             PARAMETER MYARRAY
             EXTERNAL ARRAY MYARRAY
             INSERT INTO foot (ONE,TWO,THREE,FOUR) VALUES ;
                (MYARRAY[1],MYARRAY[2],MYARRAY[3],MYARRAY[4])
             MYARRAY [1] = "100"
             MYARRAY [2] = "200"
             MYARRAY [3] = "300"
             MYARRAY [4] = "400"
    
             USE CURDIR() + "foot.dbf"
             INSERT INTO foot (ONE,TWO,THREE,FOUR) VALUES ;
                (MYARRAY[1],MYARRAY[2],MYARRAY[3],MYARRAY[4])
          ENDPROC
    
          PROCEDURE INIT
             SET UDFPARMS TO REFERENCE
             CREATE TABLE foot ;
                (ONE C(10),TWO C(10), THREE C(10), FOUR C(10))
          ENDPROC
    
          ENDDEFINE
                        
  2. After the OLE file is compiled, run the following code:

          CLEAR
          CLEAR ALL
          DIMENSION MYARRAY[4]
          MYARRAY(1) = "1"
          MYARRAY(2) = "2"
          MYARRAY(3) = "3"
          MYARRAY(4) = "4"
          OX = CREATEOBJECT("OLEtest.arraytest")
          OX.DOIT(@MYARRAY)
          ?OX.Name
          ?"MyArray from Calling Program"
          DISPLAY MEMORY LIKE MYARRAY
          RELEASE OX
          RELEASE MYARRAY
          USE foot
          BROWSE NOWAIT
                        
  3. Notice the first record of table "foot" contains the values placed in the array by the calling program. The second record contains the values PROCEDURE DOIT placed in the array. The DISPLAY MEMORY LIKE MYARRAY command, however, contains the original values of the array. Even though it appears that we are passing the array by reference to the OLE object, Microsoft Visual FoxPro is passing it by value.


Keywords: kbprb kbcode KB171438