4D v13.4

Identifiers

Home

 
4D v13.4
Identifiers

Identifiers  


 

 

This section describes the conventions for naming various objects in the 4D language. The names for all objects follow these rules:

  • 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.
  • Periods, slashes, quotation marks and colons are not allowed.
  • 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 denote 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 denote a field by first specifying the table to which the field 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 denote 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).

An interprocess variable can have up to 31 characters, not including the <> symbols.

Examples

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

You denote 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 31 characters.

Examples

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

You denote a local variable with a dollar sign ($) followed by its name. A local variable name can contain up to 31 characters, not including the dollar sign.

Examples

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

Arrays  

You denote an array by using its name, which is the name you passed to the array declaration (such as ARRAY LONGINT) when you created 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 31 characters, not including the <> symbols.

Examples

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

Process Arrays
You denote 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 31 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 ($). An local array name can contain up to 31 characters, not including the dollar sign.

Examples

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

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})}

Forms  

You denote 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))

Methods  

You denote 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")
  ` And this Plug-In command expects a method name
 WR ON ERROR("WR HANDLE ERRORS")

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 denote 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

 WR BACKSPACE(wrArea;0)
 $pvNewArea:=PV New offscreen area

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.

TypeMax. LengthExample
Table31[Invoices]
Field31[Employees]Last Name
Interprocess Variable<> + 31<>vlNextProcessID
Process Variable31vsCurrentName
Local Variable$ + 31$vlLocalCounter
Form31"My Custom Web Input"
Form object31"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"

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 to identify the object. It is up to you to ensure that you use unique names for the parts of your database.

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.

 
PROPERTIES 

Product: 4D
Theme: Language definition

 
SEE ALSO 

Arrays
Constants
Data Types
Methods
Operators
Pointers
Variables