Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Passing object array
Message
From
01/05/2019 13:25:54
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
01668317
Message ID:
01668332
Views:
53
Sorin,

Thanks for looking at this for me. I was under the impression by what Rick S. says that this is a way to pass an entire array to a different method (CallMethod) by attaching the array as a property of an object.

To me, without the additional array elements or rows being attached to the property makes this technique questionable as to it's value if it only attaches the first array element and none of the others.


>Jeff,
>
>
ADDPROPERTY(loObj, "aItems[1]", laItems)
>does 2 things:
>1. Defines the property array aItems with 1 element (i.e. "aItems[1]" )
>2. Assigns the value of the first element of laItems to all elements of loObj.aItems
>A reference to laItems (with no index) is the same as referring to laItems[1], even though laItems may have more than one element.
>In the same way, the line of code ADDPROPERTY(loObj, "aItems[7]", laItems) would define the array property loObj.aItems with 7 elements and assign the value of laItems[1] to all 7 elements of loObj.aItems
>
>As for the property array loObj.aItems; attempting to reference an element index beyond the number of elements specified in the array definition in step 1 would result in the error that you're seeing ("Array dimensions are invalid")
>*
>
>>
>>I'm still confused as to what I'm seeing even after understanding what you said about the addproperty using the literal string to declare the array. I understand and have fixed my code.
>>
>>But, try this new code and the array that is passed in the object does not contain the second array element - only one element which is 'Rick'.
>>
>>Try my fixed code that is slightly enhanced that tries to access the 2nd element of the passed array and it isn't found and crashes with 'Array dimensions are invalid'.
>>
>>Also, see my variable lnElementCount in the CallMethod and the value is always 1. I guess I'm not seeing the entire array being passed - just the first element.
>>
>>***************************************************
>>***************************************************
>>Yes, FoxPro arrays are a nightmare!!!
>>***************************************************
>>***************************************************
>>local x
>>declare laItems[2]
>>
>>laItems[1] = "Rick"
>>laItems[2] = "Markus"
>>
>>loObj = CREATE("Empty")
>>ADDPROPERTY(loObj,"aItems[1]",laItems)
>>SET STEP ON
>>x = CallMethod(loObj,1)
>>*x is 'Rick'
>>?x
>>
>>loObj = .null.
>>release loObj
>>loObj = CREATE("Empty")
>>ADDPROPERTY(loObj,"aItems[1]",laItems)
>>SET STEP ON
>>x = CallMethod(loObj,2)
>>*x should be 'Markus', but it crashes in CallMethod
>>?x
>>
>>
>>RETURN
>>
>>FUNCTION CallMethod(loObj,tnElementNo)
>>local x as Object,lnElementCount
>>local loEx as Exception
>>local lcMsg
>>lnElementCount = alen(loObj.aItems,1)
>>?lnElementCount
>>try
>> x = loObj.aItems[tnElementNo]
>> ?x
>>catch to loEx
>> lcMsg = loEx.Message
>> ?lcMsg
>>endtry
>>
>>return x
>>*return loObj.aItems[1]
>>ENDFUNC
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform