4D has its own programming language. This built-in language, consisting of more than 1000 commands, makes 4D a powerful development tool for database applications on desktop computers. You can use the 4D language for many different tasks—from performing simple calculations to creating complex custom user interfaces. For example, you can:
Programmatically access any of the record management editors (order by, query, and so on),
Create and print complex reports and labels with the information from the database,
Communicate with other devices,
Manage documents,
Import and export data between 4D databases and other applications,
Incorporate procedures written in other languages into the 4D programming language.
The flexibility and power of the 4D programming language make it the ideal tool for all levels of users and developers to accomplish a complete range of information management tasks. Novice users can quickly perform calculations. Experienced users without programming experience can customize their databases. Experienced developers can use this powerful programming language to add sophisticated features and capabilities to their databases, including file transfer and communications. Developers with programming experience in other languages can add their own commands to the 4D language.
The 4D programming language is expanded when any of the 4D modules are added to the application. Each module includes language commands that are specific to the capabilities they provide.
This manual describes the 4D "classic" language commands and constants.
If you are looking for an overall presentation of the 4D Language basics and concepts, please go to the 4D Language Concepts section on the developer.4d.com web site, where you will find all information about how to use the 4D Language.
Starting with 4D v15, 4D's Method editor uses the international "English-US" language by default, regardless of the 4D version or local system settings. This feature neutralizes any regional variations that might disrupt code interpretation between 4D applications (date formats for instance); and in French versions of 4D, commands and constants are now written in "English-US" as is already the case in other languages.
This default setting provides 4D developers with several advantages:
It facilitates code sharing between developers, regardless of their country, regional settings, or the 4D version used. A 4D method can now be exchanged by simple copy/paste, or saved in a text file, with no compatibility issues.
It also makes it possible to include 4D methods in source control tools, which often require exports to be independent from regional settings and languages.
This setting can be disabled using the "Use regional system settings" option in the 4D Preferences dialog box (see the Is a list).
The English-US settings may have several effects on the way you write methods. This concerns code written in development mode as well as formulas in deployed applications. In this mode, code must comply with following rules:
Decimal separators for real numbers must now be periods (".") in all versions (and not commas (",") as is the custom in French, for example).
Date constants must now use the ISO format (!YYYY-MM-DD!) in all versions.
Command and constant names must be in English (this change only concerns French versions of 4D, since this was already the case with other languages).
Note: The Method editor includes specific mechanisms that automatically fix incorrect entries if necessary.
The following table illustrates differences between code in 4D v15 (or higher) and in previous versions:
Code sample in methods/formulas
4D v15 and higher (default mode, all versions)
a:=12.50
b:=!2013-12-31!
Current date
4D v14 or 4D v15 (preference checked, US version, for instance)
a:=12.50
b:=!12/31/2013!
Current date
4D v14 or 4D v15 (preference checked, French version)
a:=12,50
b:=!31/12/2013!
Date du jour
Note: When the preference is checked, real and date formats are based on system settings.
In this manual, several writing conventions are used:
Following the example of the 4D Method editor, commands are written in all caps using special characters, e.g.: CLOSE DOCUMENT. Functions (commands that return a value) start with a capital letter and continue in lower case, e.g.: Change string.
In the command syntax, the { } characters (braces) indicate optional parameters. For example, SET DEFAULT CENTURY (century{; pivotYear}) means that the pivotYear parameter may be omitted when calling the command.
In the command syntax, the | character indicates an alternative. For example, Table(tableNum | aPtr) indicates that the function accepts either a table number or a pointer as parameter.
In certain examples in this documentation, a line of code may be continued onto the following line(s) due to lack of space. However, you should type these examples as a single line of code without using carriage returns.