Use 4D Write Pro documents as input forms

Automatically translated from English

Do you want to avoid users accidentally modifying a particular 4D Write Pro document (fully or partially)? Are you interested in keeping some parts of a document untouched (e.g., giving users the ability to fill in fields in a non-disclosure agreement while ensuring that none of the information in the document is altered or changed in any way)? If you’re nodding your head, then keep reading! 4D v18 R3 lets you keep parts of your documents protected, or in other words: “non-editable“.

HDI: 4DWP document protection

In the example below, we’ve created a form using a 4D Pro document where the protected and unprotected areas are clearly identifiable (enterable areas shown in white, unchangeable areas shown in gray):

Two steps are used to define protection in a document:

  • First step- Define which part of the document will be protected or not (by default all parts will be protected).
  • Second step – Activate the document protection flag so that the first settings are taken into account.

New attributes

How to proceed? A new command isn’t needed, because two new attributes have been created to be used with the well-known command, WP SET ATTRIBUTES: wk protected and wk protection enabled. The first attribute (wk protected) can be set to almost any kind of target belonging to a document (e.g., paragraph, table, section, rows in a table, anchored pictures, etc.). Inheritance will be managed, so if you protect a section, there’s no need to protect paragraphs of this section because they’ll be protected by default. However, it’s worth noting that you can also unprotect a single paragraph inside of a protected section.

Keep in mind

The only thing you need to pay attention to is the order of the targets … which makes perfect sense. For example, if you protect a section, you can always unprotect a paragraph within that section. But the opposite is not true. If you protect a paragraph and then unprotect the section to which it belongs, the protection of the paragraph will be lost.

Code sample

You have a document that must be fully protected except for a couple of areas that must be filled in by the end user. Here’s how to set up this document:

// set full parts of document protected
WP SET ATTRIBUTES(WParea;wk protected;wk true)
// then remove protection on three ranges based on bookmarks
$range:=WP Bookmark range(WParea;"Name")
WP SET ATTRIBUTES($range;wk protected;wk false)
$range:=WP Bookmark range(WParea;"Firstname")
WP SET ATTRIBUTES($range;wk protected;wk false)
$range:=WP Bookmark range(WParea;"City")
WP SET ATTRIBUTES($range;wk protected;wk false)
// Finally activate the document protection
WP SET ATTRIBUTES(WParea;wk protection enabled;wk true)

In order to see a demonstration of this feature, check out the HDI above and the documentation.

 

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.