4D v16.3

Identifiers

Home

 
4D v16.3
Identifiers

Identifiers  


 

 

This section describes the conventions for naming various objects in the 4D language (variables, tables, forms, etc.):

  • A name must begin with an alphabetic character or an underscore.
  • Thereafter, the name can include alphabetic characters, numeric characters, the space character, and the underscore character ("_").
  • Commas, slashes, quotation marks, and colons are not allowed.
  • Periods (".") and brackets ("[ ]") are not allowed in table names, fields, methods, or variables when object notation is enabled. (see Object Notation)
  • Characters reserved for use as operators, such as * and +, are not allowed.
  • 4D ignores any trailing spaces.

Note: Additional rules need to be respected when objects need to be handled via SQL: only the characters _0123456789abcdefghijklmnopqrstuvwxyz are accepted, and the name must not include any SQL keywords (command, attribute, etc.). The "SQL" area of the Inspector in the Structure editor automatically indicates any unauthorized characters in the name of a table or field.

Tables  

You designate a table by placing its name between brackets: [...]. A table name can contain up to 31 characters.

Examples

 DEFAULT TABLE([Orders])
 FORM SET INPUT([Clients];"Entry")
 ADD RECORD([Letters])

Fields  

You designate a field by first specifying the table to which it belongs. The field name immediately follows the table name. A field name can contain up to 31 characters.

Examples

 [Orders]Total:=Sum([Line]Amount)
 QUERY([Clients];[Clients]Name="Smith")
 [Letters]Text:=Capitalize text([Letters]Text)

You designate an interprocess variable by preceding the name of the variable with the symbols (<>) — a “less than” sign followed by a “greater than” sign.

Note: This syntax can be used on both Windows and Macintosh. In addition, on Macintosh only, you can use the diamond (Option-Shift-V on US keyboard).

The name of an interprocess variable can be up to 255 characters(*), not including the <> symbols.

(*) 31 characters if the "Save methods as Unicode" compatibility option is deselected. (see Compatibility page)

Examples

 <>vlProcessID:=Current process
 <>vsKey:=Char(KeyCode)
 If(<>vtName#"")

You designate a process variable by using its name (which cannot start with the <> symbols nor the dollar sign $). A process variable name can contain up to 255 characters(*).

(*) 31 characters if the "Save methods as Unicode" is deselected. (see Compatibility page)

Examples

 <>vrGrandTotal:=Sum([Accounts]Amount)
 If(bValidate=1)
    vsCurrentName:=""

You designate a local variable by placing a dollar sign ($) before the variable name. A local variable name can contain up to 255 characters(*), not including the dollar sign.

(*) 31 characters if the "Save methods as Unicode" is deselected. (see Compatibility page)

Examples

 For($vlRecord;1;100)
    If($vsTempVar="No")
       $vsMyString:="Hello there"

Arrays  

You designate an array by using its name, which is the name you pass to an array declaration (such as ARRAY LONGINT) when you create the array. Arrays are variables, and from the scope point of view, like variables, there are three different types of arrays:

  • Interprocess arrays,
  • Process arrays,
  • Local arrays.

Interprocess Arrays
The name of an interprocess array is preceded by the symbols (<>) — a “less than” sign followed by a “greater than” sign.

Note: This syntax can be used on both Windows and Macintosh. In addition, on Macintosh only, you can use the diamond (Option-Shift-V on US keyboard).

An interprocess array name can contain up to 255(*) characters, not including the <> symbols.

Examples

 ARRAY TEXT(<>atSubjects;Records in table([Topics]))
 SORT ARRAY(<>asKeywords;>)
 ARRAY INTEGER(<>aiBigArray;10000)

Process Arrays
You designate a process array by using its name (which cannot start with the <> symbols nor the dollar sign $). A process array name can contain up to 255(*) characters.

Examples

 ARRAY TEXT(atSubjects;Records in table([Topics]))
 SORT ARRAY(asKeywords;>)
 ARRAY INTEGER(aiBigArray;10000)

Local Arrays
The name of a local array is preceded by the dollar sign ($). A local array name can contain up to 255(*) characters, not including the dollar sign.

Examples

 ARRAY TEXT($atSubjects;Records in table([Topics]))
 SORT ARRAY($asKeywords;>)
 ARRAY INTEGER($aiBigArray;10000)

(*) 31 characters if the "Save methods as Unicode" option is deselected. (see Compatibility page)

Elements of arrays
You reference an element of an interprocess, process or local array by using the curly braces("{ }"). The element referenced is denoted by a numeric expression.

Examples

  ` Addressing an element of an interprocess array
 If(<>asKeywords{1}="Stop")
    <>atSubjects{$vlElem}:=[Topics]Subject
    $viNextValue:=<>aiBigArray{Size of array(<>aiBigArray)}
 
  ` Addressing an element of a process array
    If(asKeywords{1}="Stop")
       atSubjects{$vlElem}:=[Topics]Subject
       $viNextValue:=aiBigArray{Size of array(aiBigArray)}
 
  ` Addressing an element of a local array
       If($asKeywords{1}="Stop")
          $atSubjects{$vlElem}:=[Topics]Subject
          $viNextValue:=$aiBigArray{Size of array($aiBigArray)}
 
Elements of two-dimensional arrays

You reference an element of a two-dimensional array by using the curly braces ({…}) twice. The element referenced is denoted by two numeric expressions in two sets of curly braces.

Examples

  ` Addressing an element of a two-dimensional interprocess array
 If(<>asKeywords{$vlNextRow}{1}="Stop")
    <>atSubjects{10}{$vlElem}:=[Topics]Subject
    $viNextValue:=<>aiBigArray{$vlSet}{Size of array(<>aiBigArray{$vlSet})}
 
  ` Addressing an element of a two-dimensional process array
    If(asKeywords{$vlNextRow}{1}="Stop")
       atSubjects{10}{$vlElem}:=[Topics]Subject
       $viNextValue:=aiBigArray{$vlSet}{Size of array(aiBigArray{$vlSet})}
 
  ` Addressing an element of a two-dimensional local array
       If($asKeywords{$vlNextRow}{1}="Stop")
          $atSubjects{10}{$vlElem}:=[Topics]Subject
          $viNextValue:=$aiBigArray{$vlSet}{Size of array($aiBigArray{$vlSet})}

When object notation is enabled (see Object Notation), you designate an object attribute (also called object property) by placing a point (".") between the name of the object (or attribute) and the name of the attribute. An attribute name can contain up to 255 characters and is case sensitive.

Examples :

 myObject.myAttribute:="10"
 $value:=$clientObj.data.address.city

Note : Additional rules apply to object attribute names (they must conform to the ECMA Script specification). For more information, see Using object notation (preview).

Forms  

You designate a form by using a string expression that represents its name. A form name can contain up to 31 characters.

Examples

 FORM SET INPUT([People];"Input")
 FORM SET OUTPUT([People];"Output")
 DIALOG([Storage];"Note box"+String($vlStage))

You designate a form object by passing its name as a string, preceded by the * parameter. An object name can contain up to 255 bytes.

Example :

 OBJECT SET FONT(*;"Binfo";"Times")

See also the Object Properties section.

Note: Do not confuse form objects (buttons, list boxes, variables that can be entered, etc.) and objects in the 4D language. 4D language objects are created and manipulated via object notation or dedicated commands. (see Objects (Language))

Methods  

You designate a method (procedure and function) by using its name. A method name can contain up to 31 characters.

Note: A method that does not return a result is also called a procedure. A method that returns a result is also called a function.

Examples

 If(New client)
    DELETE DUPLICATED VALUES
    APPLY TO SELECTION([Employees];INCREASE SALARIES)

Tip: It is a good programming technique to adopt the same naming convention as the one used by 4D for built-in commands. Use uppercase characters for naming your methods; however if a method is a function, capitalize the first character of its name. By doing so, when you reopen a database for maintenance after a few months, you will already know if a method returns a result by simply looking at its name in the Explorer window.

Note: When you call a method, you just type its name. However, some 4D built-in commands, such as ON EVENT CALL, as well as all the Plug-In commands, expect the name of a method as a string when a method parameter is passed. Example:

Examples

  ` This command expects a method (function) or formula
 QUERY BY FORMULA([aTable];Special query)
  ` This command expects a method (procedure) or statement
 APPLY TO SELECTION([Employees];INCREASE SALARIES)
  ` But this command expects a method name
 ON EVENT CALL("HANDLE EVENTS")

Methods can accept parameters (arguments). The parameters are passed to the method in parentheses, following the name of the method. Each parameter is separated from the next by a semicolon (;). The parameters are available within the called method as consecutively numbered local variables: $1, $2,…, $n. In addition, multiple consecutive (and last) parameters can be addressed with the syntax ${n}where n, numeric expression, is the number of the parameter.

Inside a function, the $0 local variable contains the value to be returned.

Examples

  ` Within DROP SPACES $1 is a pointer to the field [People]Name
 DROP SPACES(->[People]Name)
 
  ` Within Calc creator:
  ` - $1 is numeric and equal to 1
  ` - $2 is numeric and equal to 5
  ` - $3 is text or string and equal to "Nice"
  ` - The result value is assigned to $0
 $vsResult:=Calc creator(1;5;"Nice")
 
  ` Within Dump:
  ` - The three parameters are text or string
  ` - They can be addressed as $1, $2 or $3
  ` - They can also be addressed as, for instance, ${$vlParam} where $vlParam is 1, 2 or 3
  ` - The result value is assigned to $0
 vtClone:=Dump("is";"the";"it")

You designate a plug-in command by using its name as defined by the plug-in. A plug-in command name can contain up to 31 characters.

Examples

 $error:=SMTP_From($smtp_id;"henry@gmail.com")

Sets  

From the scope point of view, there are two types of sets:

  • Interprocess sets
  • Process sets.

4D Server also includes:

  • Client sets.

Interprocess Sets
A set is an interprocess set if the name of the set is preceded by the symbols (<>) — a “less than” sign followed by a “greater than” sign.

Note: This syntax can be used on both Windows and Macintosh. In addition, on Macintosh only, you can use the diamond (Option-Shift-V on US keyboard).

An interprocess set name can contain up to 255 characters, not including the <> symbols.

Process Sets
You denote a process set by using a string expression that represents its name (which cannot start with the <> symbols or the dollar sign $). A set name can contain up to 255 characters.

Client Sets
The name of a client set is preceded by the dollar sign ($). A client set name can contain up to 255 characters, not including the dollar sign.

Note: Sets are maintained on the Server machine. In certain cases, for efficiency or special purposes, you may need to work with sets locally on the Client machine. To do so, you use Client sets.

Examples

  ` Interprocess sets
 USE SET("<>Deleted Records")
 CREATE SET([Customers];"<>Customer Orders")
 If(Records in set("<>Selection"+String($i))>0)
  ` Process sets
    USE SET("Deleted Records")
    CREATE SET([Customers];"Customer Orders")
    If(Records in set("<>Selection"+String($i))>0)
  ` Client sets
       USE SET("$Deleted Records")
       CREATE SET([Customers];"$Customer Orders")
       If(Records in set("$Selection"+String($i))>0)

From the scope point of view, there are two types of named selections:

  • Interprocess named selections
  • Process named selections.

Interprocess Named Selections
A named selection is an interprocess named selection if its name is preceded by the symbols (<>) — a “less than” sign followed by a “greater than” sign.

Note: This syntax can be used on both Windows and Macintosh. In addition, on Macintosh only, you can use the diamond (Option-Shift-V on US keyboard).

An interprocess named selection name can contain up to 255 characters, not including the <> symbols.

Process Named Selections
You denote a process named selection by using a string expression that represents its name (which cannot start with the <> symbols nor the dollar sign $). A named selection name can contain up to 255 characters.

Examples

  ` Interprocess Named Selection
 USE NAMED SELECTION([Customers];"<>ByZipcode")
  ` Process Named Selection
 USE NAMED SELECTION([Customers];"<>ByZipcode")

In the single-user version, or in Client/Server on the Client side, there are two types of processes:

  • Global processes
  • Local processes.

Global Processes
You denote a global process by using a string expression that represents its name (which cannot start with the dollar sign $). A process name can contain up to 255 characters.

Local Processes
You denote a local process if the name of the process is preceded by a dollar ($) sign. The process name can contain up to 255 characters, not including the dollar sign.

Example

  ` Starting the global process "Add Customers"
 $vlProcessID:=New process("P_ADD_CUSTOMERS";48*1024;"Add Customers")
  ` Starting the local process "$Follow Mouse Moves"
 $vlProcessID:=New process("P_MOUSE_SNIFFER";16*1024;"$Follow Mouse Moves")

The following table summarizes 4D naming conventions.

IdentifierMax. LengthExample
Table31[Invoices]
Field31[Employees]Last Name
Interprocess Variable/Table<> + 255(*)<>vlNextProcessID
Process Variable/Table255(*)vsCurrentName
Local Variable/Table$ + 255(*)$vlLocalCounter
Object attributes255$o.myAttribute
Form31"My Custom Web Input"
Form object255"MyButton"
Interprocess Array<> + 31<>apTables
Process Array31asGender
Local Array$ + 31$atValues
Method 31M_ADD_CUSTOMERS
Plug-in Routine31WR INSERT TEXT
Interprocess Set<> + 255 "<>Records to be Archived"
Process Set255 "Current selected records"
Client Set$ + 255 "$Previous Subjects"
Named Selection255 "Employees A to Z"
Interprocess Named Selection<> + 255 "<>Employees Z to A"
Local Process$ + 255 "$Follow Events"
Global Process255 "P_INVOICES_MODULE"
Semaphore255"mysemaphore"

(*) 31 characters if the "Save methods as Unicode" compatibility option is deselected.  (see Compatibility page)

Note: If non-Roman characters are used in the names of the identifiers, their maximum size may be smaller.

Be sure to use unique names for the different elements in your database. If a particular object has the same name as another object of a different type (for example, if a field is named Person and a variable is also named Person), 4D uses a priority system.

4D identifies names used in procedures in the following order:

1. Fields
2. Commands
3. Methods
4. Plug-in routines
5. Predefined constants
6. Variables.

For example, 4D has a built-in command called Date. If you named a method Date, 4D would recognize it as the built-in Date command, and not as your method. This would prevent you from calling your method. If, however, you named a field “Date”, 4D would try to use your field instead of the Date command.



See also 

Arrays
Constants
Data Types
Methods
Operators
Pointers
Variables

 
PROPERTIES 

Product: 4D
Theme: Language definition

 
HISTORY 

 
ARTICLE USAGE

4D Language Reference ( 4D v16)
4D Language Reference ( 4D v16.1)
4D Language Reference ( 4D v16.2)
4D Language Reference ( 4D v16.3)