DOCUMENT:Q130224 10-FEB-2000 [foxpro] TITLE :PRB: Cannot Pass an Array Member to a Procedure PRODUCT :Microsoft FoxPro PROD/VER:WINDOWS:3.0 OPER/SYS: KEYWORDS:kbcode ====================================================================== ------------------------------------------------------------------------------- The information in this article applies to: - Microsoft Visual FoxPro for Windows, version 3.0 ------------------------------------------------------------------------------- SYMPTOMS ======== An array that is declared as a member of a class cannot be passed by reference to a function or a method. For example, if you declare an array as a property of a form, the error "Alias 'this' is not found" is displayed when a method is called as follows: This.pNewFunction(@this.atest) CAUSE ===== Visual FoxPro always passes object properties by value. Object properties cannot be passed by reference. WORKAROUND ========== An alternative is to pass the array name to a method, and manipulate the array or a copy of the array. The following example code defines a form with a command button. When the command button is clicked, a function is called that adds 10 to each element of an array declared as a property of the command button. The same method can be used in the Form Designer. Sample Code ----------- PUBLIC oform oform=CREATEOBJECT('frmtest') oform.Show DEFINE CLASS frmtest AS FORM ADD OBJECT cmd1 AS cmd ENDDEFINE DEFINE CLASS cmd AS COMMANDBUTTON DIMENSION aprop[10] PROCEDURE init LOCAL ii FOR ii = 1 TO 10 This.aprop[ii]=ii ENDFOR ENDPROC PROCEDURE click LOCAL ii THIS.ADDEM(This, 'aprop') ACTIVATE SCREEN FOR ii =1 TO 10 ?This.aprop[ii] ENDFOR ENDPROC * Two parameters are passed to the procedure: a reference to the object, * and the array name. PROCEDURE ADDEM LPARAMETERS oref, cprop local ii, atemp[1] =ACOPY(oref.&cprop,atemp) & Makes a copy of the member array. FOR ii = 1 TO aLEN(oref.&cprop) atemp[ii]=atemp[ii] + 10 ENDFOR =ACOPY(atemp,oref.&cprop) ENDPROC ENDDEFINE STATUS ====== This behavior is by design. Additional query words: VFoxWin ====================================================================== Keywords : kbcode Technology : kbVFPsearch kbAudDeveloper kbVFP300 Version : WINDOWS:3.0 ============================================================================= THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY. Copyright Microsoft Corporation 2000.