PRIVATE

From Lianjapedia
Jump to: navigation, search

Purpose

Declare memory variables private to a procedure or program and optionally assign a data type and value

Syntax

PRIVATE <variable1> [AS <datatype>] [, <variable2> [AS <datatype>] ...] | ALL [EXCEPT | LIKE <skeleton>]

See Also

DECLARE, DIMENSION, DO, DISPLAY MEMORY, LOCAL, NAMESPACE, NAMESPACE(), PARAMETERS, PUBLIC, SET LOCAL, SET STRICT, STORE, VARINFO()

Description

The PRIVATE command provides a facility for declaring memory variables or arrays which are local to a procedure or program. When the procedure or program returns, all of the memory variables or arrays that were declared by PRIVATE, are released. The memory variables are initially declared as logicals with the value .F. (if CLIPPER is set ON they are defined as 'U'). If the optional = <value> clause is included, then the specified value is assigned to the variable.

Memory variables and arrays declared with the optional AS <datatype> clause are subject to data type checking when a value is assigned. An attempt to assign a value of an incompatible data type will fail and return error 306. The following <datatype> values can be specified:

  • ARRAY
  • CHARACTER
  • CLASSNAME
  • CURRENCY
  • DATE
  • DATETIME
  • LOGICAL
  • NUMERIC
  • OBJECT

You can declare PRIVATE memory variables with the same name as other memory variables, which were declared at lower levels. Any procedures or programs that are called can access these private memory variables. Any memory variables or arrays that need to be accessed globally should be declared using the PUBLIC command. By default any memory variables declared at the Lianja Developer development prompt, are declared as PUBLIC memory variables, and any others are declared as PRIVATE memory variables.

The ALL option allows you to define all current memory variables as private. The ALL EXCEPT <skeleton> allows the user to define all the current memory variables that do not match the wildcard <skeleton> as private. The ALL LIKE <skeleton> option allows you to define all the current memory variables that match the wildcard <skeleton> specification as private. PRIVATE ALL LIKE <skeleton> and ALL EXCEPT <skeleton> will privatize the memory variables that exist as public when used in a lower level procedure.

See DECLARE or DIMENSION for more details on array declaration.

Example

private i as numeric, j as character, k 
i = 42
? k
.F.