When a 4D Write Pro document is in edit mode, it’s often helpful to know if it has actually been modified by the end user. Based on this information, actions or interfaces can be adjusted to be more user-friendly.
Starting with 4D v19 R7, this is now easier than ever.
DEMO DATABASE
MODIFIED DOCUMENTS
A document can be modified in different ways. Either:
- by programming using one of the many commands or
- by the end-user himself.
A modified document must generally be saved, whether in terms of content (addition, modification, deletion of text, tables, or images…) or appearance (style, margins, orientation, colors…).
In any case, you must be able to offer the possibility to save it via a button or a menu, and in the extreme case where the user would like to leave without having saved it, be able to offer him a catch-up option (“do you want to save…?”).
This is now very quickly done by testing the new document.modified attribute.
The principle of this attribute is straightforward. When the document is created or loaded, its value is set to False. Then, as soon as the document is modified (by programming or user action), the value automatically changes to True.
It becomes straightforward to make the right decisions 🙂
- Update the interface
OBJECT SET ENABLED(*; "btnSave";WParea.modified) // true or false
- Confirm saving
If (Form event code=On Unload)
If (WParea.modified)
CONFIRM("Would you like to save the document ?"; "Save"; "Discard")
If (ok=1)
// do what you have to do
End if
End if
End if
Whether it’s a space deleted or a comma added, a single character bolded or italicized, it will set the document.modified to True. Even in case of an undo, document.modified will remain True.
It is, however, possible to force the value of this attribute by programming, for example, once the document has been saved.
If (WParea.modified)
// save document
// (…)
// then set the status to false
WParea.modified:=False // will stay false until next document modification
End if
… OR NOT MODIFIED?
Some actions can only change the appearance of the documents without actually changing the document’s content; these are the view properties.
You can change the zoom factor, display or not the horizontal and vertical rulers, choose to show the invisible characters, formulas, headers or footers, etc. None of this will be saved. This means that the document is not modified and, therefore, the document.modified attribute remains False. See the documentation about this new attribute.
Conclusion
This new and straightforward property will quickly detect changes inside a document and perform actions accordingly. Either transparently (making automatic saves when a document remains open, for example) or modifying the interface intelligently according to the circumstances!