4D Write Pro packs in a lot of commands and functions allowing you to create and handle complex documents by programming, documents which include pictures and text! Today, 4D Write Pro gets its own commands to insert and read text without needing to use commands originally designed for Styled Text! Thanks to these new commands, your code takes full advantage of the 4D Write Pro programming concepts, i.e. objects and ranges. Thus, your code is more elegant and easier to read!
The WP SET TEXT command allows you to write text at any position inside a document. This command is used the same way as most of the “Insert” commands in 4D Write Pro.
It takes three arguments: the range object (where the text should be inserted), the text itself, then a constant to define if the text should be placed before, after, or replace the range. And you’re good to go!
WP SET TEXT($range;vText;wk append)
With the WP Get text command, you can read text from any position in a document. The expressions contained in the range (if any) can be returned either as evaluated, as the source code, or as a simple non-breaking space (useful to keep indexes of the characters).
vText1:=WP Get text($range;wk expressions as value)
vText2:=WP Get text($range;wk expressions as source)
vText3:=WP Get text($range;wk expressions as space)
For example, if your text is “Today is the <<current date>>.“ (where <<current date>> is a 4D expression), you will be able to get either:
“Today is the 08/10/2018.”, if you pass wk expression as value as parameter.
“Today is the current date.”, if you pass wk expression as source as parameter.
“Today is the .”, if you pass wk expression as space as parameter (note the space added before the “.”)