This is the legacy 4D documentation web site. Documentations are progressively being moved to developer.4d.com |
|||||||||||||||||||||||||||||||||||
|
4D v20
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.
You can control how formulas are displayed in your documents:
By default, 4D formulas are displayed as values. When you insert a 4D formula, 4D Write Pro computes and displays its current value. If you wish to know which formula is displayed, you need to display it as a reference.
To display formulas as references, you can:
When formulas are displayed as references, the source text of the formula appear in your document, with a gray background by default (can be customized using the wk formula highlight) selector.
For example, you have inserted the current date along with a format, the date is displayed:
If you display formulas as references, the reference is displayed:
By default, when formula references are displayed, the source text of the formula is written in the document. When you work on sophisticated templates using tables for example, and when source formulas are complex, the design could be confusing:
In this case, you can display formula references as symbols, so that the document is easier to read:
To display formula references as symbols, you can:
You can always get the source text of a formula in a tip that is displayed when you hover on the symbol:
Note: The tip is actually available whatever the formula display mode.
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 v20)