Wiki Home

Set UDFParms

Namespace: Wiki
SET UDFPARMS sets the default for parameters sent to functions to passing by value (the default) or by reference. (Note that the difference between procedures and functions is how you call the routine, not on how the routine is declared.)

This from the Hackers Guide:
In FoxPro, by default, parameters are passed to procedures by reference and to functions by value. (But it's the call that determines whether you have a procedure or function, not the routine's definition.)

SET UDFPARMS lets you change the default, and muck up your system worse than you ever anticipated. If you set UDFPARMS to REFERENCE, all parameters are passed to functions by reference. Don't do that!

You can always pass a parameter to a function by reference by putting an "@" in front of it in the function call. This is a local, readable solution to the problem. Changing UDFPARMS can have all kinds of unforeseen effects on your code and on other people's code that you use.

Similarly, you can pass a parameter to a procedure by value by converting it into an expression. This is as simple as:
DO MeddlingProcedure WITH lcLeaveMeAlone && won't work
DO MeddlingProcedure WITH ( lcLeaveMeAlone ) && will work 

One place where changing UDFPARMS had an extremely adverse effect was in FPW2.x the code in GENXTAB.PRG breaks and the errors that occur at runtime misdirect you from the root cause of the problem. I do not know if the current version of the VFP code are affected the same way or not.

See Disappearing Public Vars for some code showing how passing by reference makes public variables disappear.

( Note, "SET UDFPARMS" is correct... "SET UDFPARAMS" is easy to type, mistakenly, and should be left here so that searches on this typo will find this correct topic. )
Contributors: Steven Black David Frankenbach Randy Pearson ?wgcs

Category Parameters
( Topic last updated: 2010.05.18 02:34:23 PM )