This is the legacy 4D documentation web site. Documentations are progressively being moved to developer.4d.com |
|||||||||||||||||||||||||||||||||||
|
4D v19
Managing formulas
|
Formula syntax | Type | Description |
This.title | Text | Title defined in wk title attribute |
This.author | Text | Author defined in wk author attribute |
This.subject | Text | Subject defined in wk subject attribute |
This.company | Text | Company defined in wk company attribute |
This.notes | Text | Notes defined in wk notes attribute |
This.dateCreation | Date | Date creation defined in wk date creation attribute |
This.dateModified | Date | Date modified defined in wk date modified attribute |
This.pageNumber (*) | Longint | Page number as it is defined:
This formula is always dynamic, it is not affected by the WP FREEZE FORMULAS command. |
This.pageCount (*) | Longint | Page count: total count of pages. This formula is always dynamic, it is not affected by the WP FREEZE FORMULAS command. |
This.document | Object | 4D Write Pro document |
(*) Important: This.pageNumber and This.pageCount must be used only directly in a 4D Write Pro formula (they must be present in the formula.source string). They will return incorrect values if they are used by the 4D language within a method called by the formula. However, they can be passed as parameters to a method called directly by the formula:
For example, to insert the page number in the footer area:
$footer:=WP Get footer(4DWP;1)
WP INSERT FORMULA($footer;Formula(This.pageNumber);wk append)
//Using Formula(myMethod) with myMethod processing This.pageNumber
//would not work correctly
Compatibility Note: Existing $wp_ variables in documents from versions prior to 4D v18 R2 are still supported and evaluated.
Date
When the Current date command, a date variable, or a method returning a date is inserted in a formula, it will automatically be transformed into text using system date short format.
Time
When the Current time command, a time variable, or a method returning a time is inserted in a formula, it must be enclosed within a String command because time type is not supported in JSON. Consider the following examples of formulas:
// This code is the best practice
$formula1:=Formula(String(Current time)) //OK
// This code will work but is usually not recommended, except after "Edit formula"
$formula2:=Formula from string("String(Current time)") //OK
// Wrong code because time values would be displayed as a longint for seconds (or milliseconds), not as a time
$formula3:=Formula from string("Current time") //NOT valid
$formula4:=Formula(Current time) //NOT valid
Table and field expressions inserted in 4D Write Pro documents support the virtual structure definition of the database. The virtual structure exposed to formulas is defined through SET FIELD TITLES(...;*) and SET TABLE TITLES(...;*) commands.
When a virtual structure is defined:
Note: When a document is displayed in "display expressions" mode, references to tables or fields that do not belong to the virtual structure are displayed with "?" characters, for example [VirtualTableName]? when the field is not defined in the virtual structure.
Download HDI database
Using commands from the Styled Text theme
Product: 4D
Theme: Managing formulas
Created: 4D v16
Modified: 4D v17 R4
Modified: 4D v18 R2
Renamed: 4D v18 R2
4D Write Pro Reference ( 4D v19)