Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Passing an array as a reference
Message
 
 
To
19/04/2008 04:59:00
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 9 SP2
Miscellaneous
Thread ID:
01311392
Message ID:
01311882
Views:
17
The getArrayRef does not return reference to an array but a copy of an array. It's simpler and clearer to use ACOPY() directly.

>I don't understand what you didn't understand. Here is another sample:
>
>Clear
>o = Createobject('myClass')
>o2 = Createobject('otherClass')
>o.PassArray(o2)
>o.ToUDF()
>MyUDF2(o,'myArray')
>o.PrintArray()
>
>Function MyUdf(taArray)
>  Local ix
>  For ix=1 To 5
>    taArray[m.ix,1] = taArray[m.ix,1] + taArray[m.ix,2]
>    ? taArray[m.ix,1],taArray[m.ix,2]
>  Endfor
>
>Function MyUDF2(toObj,tcArrayName)
>  a = toObj.getArrayRef(m.tcArrayName)
>  Local ix
>  For ix=1 To 5
>    a[m.ix,1] = -a[m.ix,1]
>    ? a[m.ix,1]
>  Endfor
>
>Define Class MyClass As Session
>  DataSession = 2
>  Dimension myArray[5,2]
>
>  Procedure Init
>    Local ix
>    For ix=1 To 5
>      This.myArray[m.ix,1] = m.ix
>      This.myArray[m.ix,2] = m.ix^2
>    Endfor
>  Endproc
>
>  Procedure PassArray(toTarget)
>    ref = This.getArrayRef('myArray')
>    toTarget.Receive(@ref)
>  Endproc
>
>  Procedure ToUDF
>    ref = This.getArrayRef('myArray')
>    MyUdf(@ref)
>  Endproc
>
>  Procedure PrintArray
>    Local ix
>    For ix=1 To Alen(This.myArray,1)
>      ? This.myArray[m.ix,1], This.myArray[m.ix,2]
>    Endfor
>  Endproc
>
>  Procedure getArrayRef(tcArrayName) As Array
>    Return @This.&tcArrayName
>  Endproc
>Enddefine
>
>Define Class otherClass As Session
>  Procedure Receive(taArray)
>    Local ix
>    For ix=1 To Alen(taArray,1)
>      ? taArray[m.ix,1], taArray[m.ix,2]
>    Endfor
>  Endproc
>Enddefine
>
Cetin
--sb--
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform