Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Passing an array as a reference
Message
From
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:
01311845
Views:
17
>>>Yes I did and I don't see how it's relevant.
>>
>>And I can't see how it is irrelevant:)
>
>Please show me how using that example to pass array property to an UDF by reference and I'll concede that it's relevant.

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
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform