4D v14.3

Compiler Commands

Home

 
4D v14.3
Compiler Commands

Compiler Commands  


 

 

The integrated compiler of 4D translates your database applications into assembly level instructions. The advantages of the compiler are:

  • Speed: Your database can run from 3 to 1,000 times faster.
  • Code checking: Your database application is scanned for the consistency of code. Both logical and syntactical conflicts are detected.
  • Protection: once your database is compiled, you can delete the interpreted code, Then, the compiled database is functionally identical to the original, except that the structure and procedures cannot be viewed or modified, deliberately or inadvertently.
  • Stand-alone double-clickable applications: compiled databases can also be transformed into stand-alone applications (.EXE files) with their own icon.

For a description of the operation of the 4D compiler, refer to the Design Reference manual.

The commands in this theme relate to the use of the compiler. They enable you to normalize data types throughout your database. The IDLE command is specifically used in compiled databases.

C_BLOBC_INTEGERC_REAL
C_BOOLEANC_LONGINTC_STRING
C_DATEC_PICTUREC_TEXT
C_GRAPHC_POINTERC_TIME
C_OBJECTIDLE

These commands, except IDLE, declare variables and cast them as a specified data type. Declaring variables resolves ambiguities concerning a variable’s data type. If a variable is not declared with one of these commands, the compiler attempts to determine a variable’s data type. The data type of a variable used in a form is often difficult for the compiler to determine. Therefore, it is especially important that you use these commands to declare a variable used in a form.

Note: To save time, you can use the option for generating and updating typing methods (called “Compiler methods”) found in the compiler window. This option automatically creates typing methods that take stock of and assign a type to all of the variables used in the database.

Arrays are variables that must follow the same rules as standard variables with respect to compilation. The array declaration commands are grouped together in the “Arrays” theme.

  • You must not give the same name to more than one method or variable. You cannot have a method with the same name as a variable.
  • Variable indirection as used in 4D version 1 is not allowed. You cannot use alpha indirection, with the section symbol (§), to indirectly reference variables. Nor can you use numeric indirection, with the curly braces ({...}), for this purpose. Curly braces can only be used when accessing specific elements of an array that has been declared. However, you can use parameter indirection.
  • You can’t change the data type of any variable or array.
  • You can’t change a one-dimensional array to a two-dimensional array, or change a two-dimensional array to a one-dimensional array.
  • You can’t change the length of string variables or of elements in string arrays.
  • Although the compiler will type the variable for you, you should specify the data type of a variable by using compiler directives where the data type is ambiguous, such as in a form.
  • Another reason to explicitly type your variables is to optimize your code. This rule applies especially to any variable used as a counter. Use variables of a long integer data type for maximum performance.
  • To clear a variable (initialize it to null), use CLEAR VARIABLE with the name of the variable. Do not use a string to represent the name of the variable in the CLEAR VARIABLE command.
  • The Undefined function will always return False. Variables are always defined.
  • Numeric operations on long integer and integer variables are usually much faster than operations on the default numeric type (real).

These principles are detailed in the following sections:

  • Using Compiler Directives, explains when and where to write compiler directives,
  • Typing Guide, describes the different types of conflicts that may occur during the compilation of 4D databases,
  • Users Page, provides additional information concerning several 4D commands,
  • Optimization Hints, offers hints to accelerate the running of applications in compiled mode.

The following are some basic variable declarations for the compiler:

 C_BLOB(vxMyBlob` The process variable vxMyBlob is declared as a variable of type BLOB
 C_BOOLEAN(◊OnWindows` The interprocess variable ◊OnWindows is declared as a variable of type Boolean
 C_DATE($vdCurDate` The local variable $vdCurDate is declared as a variable of type Date
 C_GRAPH(vg1;vg2;vg3` The 3 process variables vg1, vg2 and vg3 are declared as variables of type Graph

In the following example, the project method OneMethodAmongOthers declares 3 parameters:

  ` OneMethodAmongOthers Project Method
  ` OneMethodAmongOthers ( Real ; Integer { ; Long } )
  ` OneMethodAmongOthers ( Amount ; Percentage { ; Ratio } )
 
 C_REAL($1` 1st parameter is of type Real
 C_INTEGER($2` 2nd parameter is of type Integer
 C_LONGINT($3` 3rd parameter is of type Long Integer
 
  ` ...

In the following example, the project method Capitalize accepts a string parameter and returns a string result:

  ` Capitalize Project Method
  ` Capitalize ( String ) -> String
  ` Capitalize ( Source string ) -> Capitalized string
 
 C_STRING(255;$0;$1)
 $0:=Uppercase(Substring($1;1;1))+Lowercase(Substring($1;2))

In the following example, the project method SEND PACKETS accepts a time parameter followed by a variable number of text parameters:

  ` SEND PACKETS Project Method
  ` SEND PACKETS ( Time ; Text { ; Text2... ; TextN } )
  ` SEND PACKETS ( docRef ; Data { ; Data2... ; DataN } )
 
 C_TIME($1)
 C_TEXT(${2})
 C_LONGINT($vlPacket)
 
 For($vlPacket;2;Count parameters)
    SEND PACKET($1;${$vlPacket})
 End for

In the following example, the project method COMPILER_Param_Predeclare28 predeclares the syntax of other project methods for the compiler:

  ` COMPILER_Param_Predeclare28 Project Method
 
 C_REAL(OneMethodAmongOthers;$1` OneMethodAmongOthers ( Real ; Integer { ; Long } )
 C_INTEGER(OneMethodAmongOthers;$2` ...
 C_LONGINT(OneMethodAmongOthers;$3` ...
 C_STRING(Capitalize;255;$0;$1` Capitalize ( String ) -> String
 C_TIME(SEND PACKETS;$1` SEND PACKETS ( Time ; Text { ; Text2... ; TextN } )
 C_TEXT(SEND PACKETS;${2}) ` ...

 
PROPERTIES 

Product: 4D
Theme: Compiler

 
SEE ALSO 

C_BLOB
C_BOOLEAN
C_DATE
C_GRAPH
C_INTEGER
C_LONGINT
C_PICTURE
C_POINTER
C_REAL
C_STRING
C_TEXT
C_TIME
IDLE

 
ARTICLE USAGE

4D Language Reference ( 4D v14 R2)
4D Language Reference ( 4D v14 R3)
4D Language Reference ( 4D v14.3)
4D Language Reference ( 4D v14 R4)

Inherited from : Compiler Commands ( 4D v11 SQL Release 6)