Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Passing object array
Message
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
01668317
Message ID:
01668320
Views:
72
>Well in your example you don't need to pass the array since it's a property and you're calling a method so you can just use `this.Array` directly. This is actually a common scenario I use to 'pass arrays' - wrap it into an object then pass the object instead of the array.
DECLARE laItems[2] 

laItems[1] = "Rick"
laItems[2] = "Markus"

loObj = CREATE("Empty")
ADDPROPERTY(loObj,"aItems[1]",laItems)
SET STEP ON 
? CallMethod(loObj)

RETURN

FUNCTION CallMethod(loObj)
return loObj.aItems[1]
ENDFUNC
>
>I hate arrays for so many reasons - the funky initialization, in ability to return arrays from functions, the cumbersome way to manipulate or modify arrays etc. In fact long ago (pre Collection class in VFP) I created some array collection wrappers to make all that easier and it solves the problem you mention above.
>
>These days it's probably a much better idea to use the FoxPro Collection class (or a custom class) in almost all places where Arrays are used.
>
>+++ Rick ---
>
>>Is there a way to pass an object array by reference?
>>
>>
lo = CREATEOBJECT("_c")
>>lo.process()
>>
>>DEFINE CLASS _c AS Custom
>>    aArray[1] = .f.
>>    
>>    PROCEDURE Process
>>    LOCAL laArray
>>        DIMENSION laArray[1]
>>SET STEP ON
>>        this.update_array(@laArray)
>>        this.update_array(@this.aArray)
>>    ENDPROC
>>
>>    PROCEDURE update_array
>>    LPARAMETERS taArray
>>    EXTERNAL ARRAY taArray
>>        taArray[1] = "test"
>>    ENDPROC
>>ENDDEFINE
>>
+++ Rick ---

West Wind Technologies
Maui, Hawaii

west-wind.com/
West Wind Message Board
Rick's Web Log
Markdown Monster
---
Making waves on the Web

Where do you want to surf today?
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform