Automatic routines using MVC models
Uses model rules with explicit validation and persistence.
Overview
Prepare an environment only if the caller does not provide one. Load the model, set operation, activate, assign values by valid IDs and run VldData before CommitData. Check relevant returns, retrieve GetErrorMessage on failure and finish deactivation/destruction according to object contract. Errors may contain field values, so minimize logging. This exercise builds a validator block without writing; CommitData is commented to identify the unexecuted persistence stage. (Sources: refs. 1–2.)
Commented example
#Include "Protheus.ch"
User Function Ed634()
// Requires an active populated model; block not invoked.
Local bValidate := {|oModel| oModel:VldData()}
// After validation, only in the authorized flow: oModel:CommitData()
ConOut(ValType(bValidate))
Return NilCreates B without validating or writing a real object. Under review: editorial example neither compiled nor run in Protheus. Check includes, release, RDD and context before testing.
- VldData is not commit. LoadValue is not a general substitute for SetValue to skip validation.
- Under review: editorial example neither compiled nor run in Protheus. Check includes, release, RDD and context before testing.

Comments
There are no approved comments yet.
Sign in with Google or Microsoft to comment.