Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Passing Array by Reference to a Form vfp6
Message
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00659071
Message ID:
00659629
Views:
30
This message has been marked as the solution to the initial question of the thread.
Here's a sample code demonstrating how to use parameter object.
loParam = Createobject("custom")
loParam.Addproperty("aReturnValues[1]", null)
loParam.Addproperty("cSample", lcSample)
...
loParam.Addproperty("cProcess", lcProcess)

DO FORM AddSamp WITH loParam 
lnNoSelected = ALEN(loParam.aReturnValues)
...
...

* AddSamp Init 
LPARAMETERS toParamObj
This.oParamObj = toParamObj  && save to form property for use in the form

* Somewhere in the form's method
...
arrayIndex = 1
DIMENSION Thisform.oParamObj.aReturnValues[nNoSelected]

FOR i = 1 TO thisform.samplist.ListCount
  IF thisform.sampList.Selected(i)
    Thisform.oParamObj.aReturnValues[arrayIndex ] = ;
            alltrim(str(thisform.CancelOk)) + "|" + ;
            alltrim(thisform.samplist.List(i)) + "|"            + ;
            alltrim(str(thisform.lnReps)) + "|" + ;
            alltrim(str(thisform.lnPackages))
    arrayIndex = arrayIndex + 1
  ENDIF
ENDFOR
...

* AddSamp Destroy
Thisform.oParamObj = Null   && Release reference to the parameter object
In the second case run form using NAME clause
do form AddSamp with lcSample, lnReps, lnPackages, 3, lcProcess NAME loAddSamp LINKED 
? loAddSam.aReturnValues[1]
...
loAddSam.Release()
>>You can return values this way from the Init only because parameters as
>> scoped to the Init. You've a couple of options here:
>>1. Create parameter object with an array property and pass it instead of array.
>
>But is it still lost, after the Init? From my tests, the reference to the array property is lost after Init.
>
>>2. Make returnarray a property of the form and instead of releasing form just hide it, copy that array to your local array and them release form.
>
>How would I access that hidden form (AddSample) from the calling object? Just issue the return function from within AddSample, then within the calling object AddSample.returnarray to access that property? and then just do AddSample.release() ?
>
>This 2nd option seems like the only way to do it...
>
>thanks for your help, thus far, it has been invaluable.
>matt
--sb--
Previous
Reply
Map
View

Click here to load this message in the networking platform