Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Pass array as a parameter
Message
De
17/11/2004 05:58:12
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Gestionnaire d'écran & Écrans
Divers
Thread ID:
00961882
Message ID:
00962092
Vues:
8
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 )
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform