Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- The Guide To Clipper - <b>parameters</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
PARAMETERS


Syntax:     PARAMETERS <memvar list>

Purpose:    To identify memory variables that receive passed values or
            references.

Argument:   <memvar list> is one or more receiving memory variables
            separated by commas.  The number of receiving variables does
            not have to match the number of parameters passed.

Usage:      Parameters are defined as either formal or actual.  Formal
            parameters are the receiving memory variables specified as
            arguments of the PARAMETERS statement.  Actual parameters
            are the arguments of the calling DO...WITH or user-defined
            function invocation.

            There are two methods of passing parameters, by value or by
            reference.  By value means that the actual parameter is
            evaluated and the result is placed in a memory location.
            When the subsequent PARAMETERS executes, the value is
            transferred to the receiving variable.  Passing by reference
            means that a pointer to the location of the actual parameter
            is passed instead of the value.  Subsequent changes to the
            formal parameter cause changes to the actual parameter.
            Thus the formal parameter is simply a reference to the
            actual parameter.

            Note that in Clipper there is no argument checking and
            therefore no requirement that the number of actual
            parameters match the number of formal parameters.  If there
            are more actual parameters than formal parameters, the extra
            actual parameters are ignored.  If there are fewer actual
            parameters than formal parameters, the extra formal
            parameters are undefined; referring to them will cause a
            runtime error.  To determine the number of actual parameters
            passed, use PCOUNT().

            Passing parameters to procedures and user-defined
            functions: The following rules apply when you pass
            memory variables and arrays to procedures and user-defined
            functions:

            Memory variables and array identifiers are passed by
            reference to procedures.  Array elements, expressions,
            variables within parentheses, and fields are passed by value
            (fields must be bounded by parentheses).

            By default, parameters to user defined functions are passed
            by value.  A memory variable, however, can be passed by
            reference if the variable is preceded by the "at" sign (@).
            Arrays are always passed by reference; array elements can
            only be passed by value.

            Passing parameters from the DOS command line: You can
            pass multiple character strings to your program from the DOS
            command line.  The character strings must be separated by
            spaces.  A parameter bounded by quotes is passed as one
            string.  For example:

               C>PROG "CLIPPER COMPILER" 5

            The routine that receives parameters from the DOS command
            should test the number of passed parameters with PCOUNT() to
            assure that critical parameters are defined.

Library:    CLIPPER.LIB


----------------------------------- Examples -------------------------------

   The following example passes parameters to a procedure.  "Memvar" and
   "array" are passed by reference while "memvar2" is passed by value:

   DECLARE array[1]
   STORE "old" TO memvar, memvar2, array[1]
   DO Proc WITH memvar, (memvar2), array

   ? memvar, memvar2, array[1]      && Result: new old new

   RETURN


   PROCEDURE Proc
   PARAMETERS new_var, new_var2, new_array

   STORE "new" TO new_var, new_var2, new_array[1]

   RETURN

   This example demonstrates passing parameters to user-defined
   functions.

   STORE 10 TO memvar, memvar2
   Modvar(@memvar, memvar2)

   ? memvar, memvar2             && Result: 20 10

   RETURN


   FUNCTION Modvar
   PARAMETER new_var, new_var2

   STORE 20 TO new_var, new_var2

   RETURN ""

   The following example demonstrates passing parameters from the DOS
   command line to the following program CLIPTEST:

   * Cliptest.prg
   PARAMETERS char, num, date, logical

   ?? TYPE("char")
   ?? TYPE("num")
   ?? TYPE("date")
   ?? TYPE("logical")

   RETURN

   Then executing CLIPTEST from DOS with the following command line:

      C>CLIPTEST string 12 CTOD(SPACE(8)) .T.

   produces the following results:

      C C C C

   When you call the same block of code as a procedure like this:

   DO Cliptest WITH "string", 12, CTOD(SPACE(8)), .T.

   the results are different:

      C N D L


See Also: DO PRIVATE PROCEDURE PUBLIC SET PROCEDURE PCOUNT()

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson