4D v16.3

Compiler Commands

Home

 
4D v16.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.
  • Execution in preemptive mode: only compiled code can be executed in a preemptive process.

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_REALC_TEXT
C_BOOLEANC_LONGINTC_DATE
C_POINTERC_PICTUREC_TIME
C_OBJECTIDLE

Compatibility note: The obsolete _o_C_GRAPH, _o_C_INTEGER and _o_C_STRING commands must no longer be used.

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).
  • If you have checked the "Can be run in preemptive processes" property for the method, the code must not call any thread-unsafe commands or other thread-unsafe methods.

These principles are detailed in the following sections:

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_LONGINT(vg1;vg2;vg3// The 3 process variables vg1, vg2 and vg3 are declared as variables of type longint

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

  // OneMethodAmongOthers Project Method
  // OneMethodAmongOthers ( Real ; Date { ; Long } )
  // OneMethodAmongOthers ( Amount ; Date { ; Ratio } )
 
 C_REAL($1// 1st parameter is of type Real
 C_DATE($2// 2nd parameter is of type Date
 C_LONGINT($3// 3rd parameter is of type Long Integer

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

  // Capitalize Project Method
  // Capitalize ( Text ) -> Text
  // Capitalize ( Source string ) -> Capitalized string
 
 C_TEXT($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 COMPILER_Param_Predeclare28 project method predeclares the syntax of other project methods for the compiler:

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



See also 

_o_C_GRAPH
_o_C_INTEGER
_o_C_STRING
C_BLOB
C_BOOLEAN
C_DATE
C_LONGINT
C_PICTURE
C_POINTER
C_REAL
C_TEXT
C_TIME
IDLE

 
PROPERTIES 

Product: 4D
Theme: Compiler

 
HISTORY 

Modified: 4D v15 R5

 
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)