How to easily handle text insertion in 4D Write Pro

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!

Database example

Two new commands have been created: WP SET TEXT and WP Get text.

Insert text

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)

Read text

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 “.”)

Roland Lannuzel
• Product Owner & 4D Expert •After studying electronics, Roland went into industrial IT as a developer and consultant, building solutions for customers with a variety of databases and technologies. In the late 80’s he fell in love with 4D and has used it in writing business applications that include accounting, billing and email systems.Eventually joining the company in 1997, Roland’s valuable contributions include designing specifications, testing tools, demos as well as training and speaking to the 4D community at many conferences. He continues to actively shape the future of 4D by defining new features and database development tools.