Microsoft KB Archive/130224

= PRB: Cannot Pass an Array Member to a Procedure =

Article ID: 130224

Article Last Modified on 2/10/2000

-

APPLIES TO


 * Microsoft Visual FoxPro 3.0 Standard Edition

-



This article was previously published under Q130224



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

PROCEDURE ADDEM LPARAMETERS oref, cprop local ii, atemp[1]
 * Two parameters are passed to the procedure: a reference to the object,
 * and the array name.

=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 KB130224

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.