Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Pass array as a parameter
Message
From
17/11/2004 12:35:22
 
 
To
17/11/2004 12:33:41
General information
Forum:
Visual FoxPro
Category:
Forms & Form designer
Miscellaneous
Thread ID:
00961882
Message ID:
00962280
Views:
7
>>>Hi Paul.
>>>
>>>does actually pass the whole array. That’s good but I thought it didn’t work this way. My UDFPARMS is set to VALUE. Is this reliable?
>>>
>>>Just to add to all the other good information that the others have given you:
>>>
>>>Parameters are passed either by reference or by value. When a parameter is passed to a function or procedure by reference, any changes made to its value in the called code are reflected in the original value in the calling program. Conversely when a parameter is passed by value, the called code can change that value but the value in the calling program remains unchanged.
>>>Visual FoxPro interprets the code being called by the mechanism by which parameters are passed. So when the calling syntax looks like this:
>>>
>>>luRetVal = CallMyFunction( param1, param2 )
>>>
>>>Visual FoxPro treats this as a Function Call and passes the parameters by value. However if the same code is called like this:
>>>
>>>DO CallMyFunction WITH param1, param2
>>>
>>>then Visual FoxPro treats this as a Procedure Call and passes the parameters by reference. The old coding rule that a “Function must always return a value” is not really true in Visual FoxPro, but it does make sense when the calling syntax is considered.
>>>You can change this default behavior in two ways. One way is to:
>>>
>>>SET UDFPARMS TO REFERENCE or SET UDFPARMS TO VALUE
>>>
>>>However, we do not consider this a good idea because it affects the way all functions in your entire application handle the parameters they are passed. (It is never a good idea to use a global solution to solve a local problem). In this case there is a simple solution because parameters can be passed by value explicitly just by enclosing them in parentheses. Thus:
>>>
>>>DO CallMyFunction WITH (param1), (param2)
>>>
>>>passes the parameters by value, even though the syntax used would normally cause them to be passed by reference. To pass parameters explicitly by reference, simply preface the parameter with the “@” symbol. (This is, by the way, the only way to pass an entire array to a procedure, function or method). So we could also make our function call and pass its parameters by reference like this:
>>>
>>>luRetVal = CallMyFunction( @param1, @param2 )
>>
>>
>>All good points, Marcia.
>>
>>One additional item. Properties can only be passed by value. You cannot pass a property by reference, even if you call it as procedure. If you try to pass a property to a function and precede it with "@", it's a syntax error.
>
>But you can put "@" before a property.
>
>For increment the confusions of the language, you can put the "@" by reference for return
>a array property value or a external scoped array variable ( a copy back ):
>
>CLEAR
>RELEASE y,x,aProp
>DIMENSION aProp[3]
>aProp = 1
>X=CREATEOBJECT('mmm')
>Y= X.BLBLA1()
>FOR i=1 TO ALEN(Y)
>	? y[m.i]
>NEXT
>Y= X.BLBLA2()
>FOR i=1 TO ALEN(Y)
>	? y[m.i]
>NEXT
>DEFINE CLASS mmm as Custom
>		DIMENSION aProp[7]
>		aProp = 2
>	
>	PROCEDURE BLBLA1
>		PRIVATE aProp
>		DIMENSION aProp[15]
>		aProp = 3
>		RETURN @m.aProp && this is the external variable ( this is a bug for me )
>	
>	PROCEDURE BLBLA2
>		PRIVATE aProp
>		DIMENSION aProp[5]
>		aProp = 4
>		RETURN @this.aProp
>ENDDEFINE
>
True, but that is returning a property as an array from a function, not passing the property (array or otherwise) to the function.
Fred
Microsoft Visual FoxPro MVP

foxcentral.net
Previous
Reply
Map
View

Click here to load this message in the networking platform