PRIVATE

Create and initialize private memory variables and arrays

Syntax

       PRIVATE <identifier> [[:= <initializer>], ... ]

Arguments

<identifier> is the name of a private variable or array to create. If the <identifier> is followed by square brackets ([ ]), an array is created and assigned to the <identifier>. When the <identifier> specification indicates an array, the syntax for specifying the number of elements for each dimension can be array[<nElements>, <nElements2>, …] or array[<nElements>][<nElements2>]… The maximum number of elements per dimension is 4096. The maximum number of dimensions is limited only by available memory.

<initializer> is the optional assignment of a value to a new private variable. An array cannot be given values with an <initializer>. An <initializer> for a private variable consists of the inline assignment operator (:=) followed by any valid Harbour expression including a literal array. If no explicit <initializer> is specified, the variable is initialized to NIL. In the case of an array, each element is initialized to NIL.

You can create and, optionally, initialize a list of variables and arrays with one PRIVATE statement if the definitions are separated by commas.

Description

The PRIVATE statement creates variables and arrays visible within the current and invoked procedures or user-defined functions. This class of variable is said to have dynamic scope. Private variables exist for the duration of the active procedure or until explicitly released with CLEAR ALL, CLEAR MEMORY, or RELEASE. When a private variable or array is created, existing and visible private and public variables of the same name are hidden until the current procedure or user-defined function terminates.

Attempting to specify a PRIVATE variable that conflicts with a previous FIELD, LOCAL, or STATIC declaration of the same name results in a fatal compiler error. This is true regardless of the scope of the declaration.

PRIVATE statements are executable statements and, therefore, must be specified within the body of a procedure or user-defined function and must follow all variable declarations, such as FIELD, LOCAL, MEMVAR, and STATIC.

In addition to the PRIVATE statement, private variables are also created in two other ways:

. Assignment to a variable that does not exist or is not visible will create a private variable .

Parameters received using the PARAMETERS statement are created as private variables with the same lifetime and visibility.

No more than 2048 private and public variables and arrays can simultaneously exist in a single program.

For more information on variable declarations and scoping, refer to the Variables section in the “Basic Concepts” chapter.

Notes

. Compatibility: The ALL, LIKE, and EXCEPT clauses of the PRIVATE statement supported by other dBASE dialects are not supported.

Examples

       .  This example creates two PRIVATE arrays and three other
          PRIVATE variables:
          PRIVATE aArray1[10], aArray2[20], var1, var2, var3
       .  This example creates a multidimensional private array using
          each element addressing convention:
          PRIVATE aArray[10][10][10], aArray2[10, 10, 10]
       .  This example uses PRIVATE statements to create and initialize
          arrays and variables:
          PRIVATE aArray := { 1, 2, 3, 4 }, ;
                aArray2 := ARRAY(12, 24)
          PRIVATE cChar := SPACE(10), cColor := SETCOLOR()

Seealso

FIELD, LOCAL, MEMVAR, PARAMETERS, PUBLIC, STATIC

MEMVAR

MEMVAR

Declares private and public variables and arrays.

Syntax

      MEMVAR <xVar>

Arguments

<xVar> Memory variable Name

Description

This command tells the compiler to resolve any reference to a memory variable designated within this list s if it possessed an explicit memory variable alias with either the M-> or MEMVAR-> prefix.Only those memory variables that do not contain any such explicit are affected by this command. Those memory variabls within macro expansions are not affected by this command.

The MEMVAR declaration must apear before any executable commands;it is similat to the LOCAL, STATIC, FIELD, PARAMETERS, FUNCTION, and PROCEDURE commands statements.

Examples

      MEMVAR y AS NUMERIC
      PROCEDURE Main()
         LOCAL n, lVar

         n := iif( lVar, "A", 3 )
         n := 2
         n := "a"
         n := seconds() + 2
         n := int( seconds() + 2 )
         y := n
         ? y
         RETURN

Tests

      See tests/testwarn.prg for more examples

Compliance

Clipper

Platforms

All

Files

None.

Seealso

LOCAL, STATIC, FIELD, PRIVATE, PUBLIC

LOCAL

LOCAL

Initializes a local memory variable or array

Syntax

      LOCAL <xVar> [:= <xInit> ]

Arguments

<xVar> Name of a memory variable or array.

<xInit> Value to be assinged to a variable or array

Description

This command created a LOCAL memory variable or array. The name of either is specified in <xVar>. If more then one variable is being initialized with the LOCAL command, separate each entry with a comma. If a variable or an array is to be assingned a start-up value, that expression may be specified in <xInit> and folling. Is Strong type compile mode is used, the Compiler will check if the value recived matchs the type specified in <xType>.

LOCAL varibles are symbols generated at run time and are resolved at compile time. The visibility and life span of a LOCAL variable or array is limited to the function or procedure in which it is defined.

No macro expansions are allowed in the LOCAL declaration statement.

No Harbour command other then FUNCTION, PROCEDURE, PUBLIC, PRIVATE, PARAMETERS, MEMVAR, STATIC and FIELD, may precede the LOCAL command.

LOCAL array reference may not be initialized (i.e., assigned values) on the same command line as the LOCAL command statement. This can be done later in the program.

LOCAL variables and arrays are not affected by the RELEASE command.

Examples

      PROCEDURE Main()
         LOCAL n, lVar

         n := iif( lVar, "A", 3 )
         n := 2
         n := "a"
         n := seconds() + 2
         n := int( seconds() + 2 )
         RETURN

Tests

      See tests/testwarn.prg for more examples

Compliance

Clipper

Platforms

All

Files

None

Seealso

FIELD, PRIVATE, PUBLIC, STATIC, MEMVAR

FIELD

FIELD

Declares a list of database field names.

Syntax

      FIELD <xField> [,<xFieldn...>  [in <cDatabase>]

Arguments

<xField> A valid field name

<xFieldn> Additional field name

<cDatabase> An valid alias name

Description

This command declares the names of fields <xField> (and <xFieldn> and following) with an optional alias identifier as <cDatabase> for each. This command allow Harbour to resolve any reference to a field specified in the field list by viewing it as a field when it is not referenced by an alias. If a field is not listed in this list and it is not explicity tagged with an alias indentifier, it may be viewed as a memory variable, which may cause run-time errors. This command has no effect on memory variables or on field reference buried within a macro expression.

Examples

      PROCEDURE Main()
         FIELD Id
         FIELD Name
         USE tests NEW
         Name := "Sales"
         Id := 5
         USE
         RETURN

Tests

      See tests/testwarn.prg

Compliance

Clipper

Platforms

All

Files

None.

Seealso

MEMVAR, PRIVATE, PUBLIC, STATIC

SP_VIEWPORT

VIEWPORT()

  Short:
  ------
  VIEWPORT() Multi-optional data entry engine

  Returns:
  --------
  Nothing

  Syntax:
  -------
  VIEWPORT([lModify],[aFields,aDesc],[aPict],[aVal],[aLook],;
            [aOther],[aEdit],[lCarry],[cTitle])

  Description:
  ------------
  Presents a generic data entry screen with multiple
  movement, search, view and editing capabilities.

  [lModify] Logical - this is (.T.) if you want to give
  the user Add,Edit,Delete, and (.F.) if not. Defaults to (.T.)

  Arrays 1-5 and array 7 must have the same # of
  elements.
  (default is # of fields in DBF). You may pass a nil
  to bypass and activate the default for any of these arrays.

  [aFields]    An array of field names. Defaults to all
  fields in DBF.

  [aDesc]   An array of field descriptions. Defaults to
  field names. You must pass [aFields] if you wish to pass
  [aDesc]

  [aPict]  is an array of PICTURES as Character
  expressions to correspond with the [aFields] array. Default is
  pictures as derived by ED_G_PIC(). If you pass this array,
  each element must contain  at least a "".

  [aVal] is an array of VALID clauses and messages
  to correspond with the [aFields] array. Each is in the form

         "{valid clause};{valid message}"

  The FIELD is represented as a token "@@"
  in the valid clause which is replaced with the current edited
  value at edit time. Note: Field values are loaded into an
  array when editing, so field names in the valid are not
  meaningful. Field name FIRST might be aValues[12]. At edit
  time, the "@@ " will be  replaced with "aValues[12]".

         i.e.
          "!empty(@@);Must not be empty"

  If you pass this array, each element must
  contain at least a "".

  [aLook]  is an array of Lookup definitions
  corresponding to the [aFields] array.
  These are delimited strings with 1-4
  component parts matching the first four parameters of SMALLS().
  Delimiter is a semicolon (;). As an example, to make a lookup
  definition corresponding to the COMPANY field in the
  [aFields] array, which will lookup on the field CORPNAME in
  the database INSTIT, titling the box "Company" and KEYBOARDing
  the contents of CORPNAME if CR pressed

             "CORPNAME;Company;%INSTIT;CORPNAME".

  If you realize that these 4 components are
  parsed and sent as parameters to SMALLS(), you will get the
  idea.

  If you pass this array, each element must
  contain at least a "".

  [aOther]  [1-9 elements] Each of elements 1-9 is a
  delimited string in the format

         "{option};{action}"

  where option is a displayed menu option and action
  is a proc to be executed. i.e.:

          "Form Letters;FORMLETR()"
          "List Myfile;FILEREAD(2,2,22,78,'FMYFILE.TXT')"

  Pass 1-9 option/proc combinations. These
  will be presented as an 'Other' menu.

  THESE PROCS MUST BE DECLARED EXTERNAL!!!

  [aEdit] an array of logicals matches the FIELDS
  array and defines which fields may be edited (.t.) and which
  are display only (.f.)  If you pass this array, each element
  must be of TYPE Logical.

  [lCarry]     Pop up 'Carry Forward' message when adding?
  True/False. Default is True.

  [cTitle]     Optional title. Default is
               "  V.I.E.W  P.O.R.T  for file: "+TRIM(ALIAS())+' '

  Examples:
  ---------
   local aFlds[fcount()]
   local aFdes[fcount()]
   local aFval[fcount()]
   local aFloo[fcount()]
   local aFedit[fcount()]
   afields(aFlds)
   afields(aFdes)
   afill(aFval,"")
   afill(aFloo,"")
   afill(aFedit,.t.)

   // valids for fields 5 and 6
   aFval[5]:="!empty(@@);Cannot be empty"
   aFval[6]:="!empty(@@);Cannot be empty"

   // lookups for fields 5 and 6
   aFloo[5] := "First;First Name;%user%;trim(first)"
   aFloo[6] := "Last;Last Name;%user%;trim(Last)"

   // 'other' menu array

   aOther := { "Read PRG;FILEREAD(1,1,23,79,'s_viewp.prg')",;
               "Do Form Letters ;FORMLETR()",;
               "Frequency Analysis;FREQANAL()" }

   VIEWPORT(.t.,aFlds,aFdes,nil,aFval,aFloo,aOther)

  Source:
  -------
  S_VIEWP.PRG

SP_SUM_AVE

SUM_AVE()

  Short:
  ------
  SUM_AVE() Interactive sum or average on a dbf field

  Returns:
  --------
  Nothing

  Syntax:
  -------
  SUM_AVE([cSumAve])

  Description:
  ------------
  Does a SUM or AVERAGE on a selected numeric field

  [csumAve] = "SUM" or "AVE". Default is "SUM"

  Examples:
  ---------
   case nChoice = 3  && sum

     SUM_AVE("SUM")

   case nChoice = 4  && average

     SUM_AVE("AVE")

  Notes:
  -------
  If sls_query() is not empty, an  optional SUM or
  AVERAGE for QUERY can be done.

  Source:
  -------
  S_SUMAV.PRG

 

SP_STAGFIELDS

STAGFIELDS()

  Short:
  ------
  STAGFIELDS() Tag fields

  Returns:
  --------
  aTagged => an array of element #'s of the tagged items

  Syntax:
  -------
  STAGFIELDS([aFieldnames],[cTitle],[cMark])

  Description:
  ------------
  Tags selected items in an array of fields, returning
  an array of element #'s of tagged items in the array of fields.

  [aFieldNames] - an array of field names. Default -
  all fields

  [cTitle]      - title for the popup. Default none

  [cMark]       - character used to mark as tagged.

                          Default is checkmark chr(251)

  Examples:
  ---------
   aTagged := STAGFIELDS()

   for i = 1 to len(aTagged)

     ?field(aTagged[i])   // fieldname

   next

  Source:
  -------
  S_TAGF.PRG