Statement PARAMETERS Foundation

Declares function parameters as variables of the storage class PRIVATE.

Syntax
PARAMETERS <Parameters,...>
Parameters
<Parameters,...>
<Parameters,...> is a comma separated list which contains the names of the function parameters. The parameters belong to the storage class PRIVATE. The values assigned to the <Parameters,...> are what was passed to the called function or procedure.
Description

"Parameter" designates a variable to which a value is assigned by the function call. The passed value is called an argument. The statement PARAMETERS declares the formal parameters of a user-defined function as variables of the storage class PRIVATE, which are created at runtime and affect the execution speed of a user-defined function or procedure.

Since the PARAMETERS statement creates PRIVATE variables, they remain visible in the program until the corresponding function or procedure is ended or until they are "hidden" in a subsequently called function or procedure.

The PARAMETERS statement is an executable statement and must therefore follow all variable declarations like MEMVAR, FIELD, LOCAL and STATIC within a function or procedure.

When the formal parameters of a function or procedure are expressed in the declaration as a list of variable names in parentheses, the parameters are of storage class LOCAL, whose references are resolved at compile time. This increases the execution speed.

Examples
PARAMETERS usage
// The example demonstrates how LOCAL variables are saved in and 
// restored from an .XPF file. 
// Two user-defined commands are formulated with the 
// #command directive, which are translated from the preprocessor 
// to a call to the procedure SaveLocal() or RestLocal(). 
// In both procedures, the formal parameters are declared with 
// PARAMETERS. 
// The parameters belong to the storage class PRIVATE and can be saved 
// and read again with the command SAVE or RESTORE. 
// With SaveLocal(), the values of LOCAL variables are assigned to the 
// parameters and the parameters are saved. 
// With RestLocal(), the LOCAL variables are passed by reference, after 
// which the value of the read PRIVATE variable (saved parameter) is 
// assigned to them. If you lengthen the parameter lists of SaveLocal() 
// and Restlocal(), more than 10 LOCAL variables can be saved. 

#command SAVE TO <(file)> LOCAL <var,...> ; 
=>      SaveLocal( <(file)>, <var> ) 

#command RESTORE FROM <(file)> LOCAL <var1> [,<varN>] ; 
=>      RestLocal( <(file)>, @<var1> [, @<varN>] ) 


  PROCEDURE Main 
     LOCAL cString:= "Xbase++", ;     // Declares LOCAL variables 
           dDate  := Date()   , ;     // and initializes them 
           nNumber:= 100      , ; 
           lLogic := .T. 

     SAVE TO TestFile ;               // Saves value of the LOCALs 
       LOCAL cString, dDate, nNumber, lLogic 

     cString := dDate := ;            // Deletes all values of the 
     nNumber := lLogic:= NIL          // locals (assigns NIL) 

     RESTORE FROM TestFile ;          // Reads the values again 
       LOCAL cString, dDate, nNumber, lLogic 

     ************************************************************ 
     * The PPO code for RESTORE FROM...LOCAL is:                * 
     *                                                          * 
     * RestLocal( "TestFile", @cString,@dDate,@nNumber,@lLogic) * 
     *                                                          * 
     * Passes the LOCAL variables by reference!                 * 
     ************************************************************ 

     ? cString                        // Result: "Xbase++" 
     ? dDate                          // Result: Date() 
     ? nNumber                        // Result: 100 
     ? lLogic                         // Result: .T. 

  RETURN 

  ** PARAMETER variables are declared as PRIVATE variables and 
  ** can therefore be stored in an .XPF file 
  PROCEDURE SaveLocal 
     PARAMETERS cFile, p1,p2,p3,p4,p5,p6,p7,p8,p9,p10 

     SAVE TO (cFile) ALL LIKE p* 
  RETURN 

  ** PARAMETER variables are declared as PRIVATE variables and 
  ** can therefore be read out of an .XPF file. 
  ** When LOCAL variables are passed by reference, they 
  ** receive the read values of the PRIVATE variable. 
  PROCEDURE RestLocal 
     PARAMETERS cFile, p1,p2,p3,p4,p5,p6,p7,p8,p9,p10 

     RESTORE FROM (cFile) ADDITIVE 
  RETURN 

Feedback

If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.