Usina BRAdvPL Guide
Sign in
← All topics
FOUNDATIONUnder review

MVC (Model View Controller)

ModelDef -> Model; ViewDef -> View; MenuDef -> actions

Separates data rules, UI and application actions.

MVC (Model View Controller)AdvPL
01 · OVERVIEW

Overview

ModelDef defines the model and its rules; ViewDef binds fields and grids to it; MenuDef supplies actions and operations. MPFormModel supports the Protheus pattern with Help handling, memory variables and default persistence. UI code should not own rules also required by automatic execution. Definition, activation, validation, persistence and cancellation are distinct steps. The community single-entity sample separates these functions; the table below summarizes responsibilities without opening tables or windows. (Sources: refs. 1–4.)

02 · SYNTAX

Syntax

ModelDef -> Model; ViewDef -> View; MenuDef -> actions
03 · PRACTICAL EXAMPLE

Commented example

#Include "Protheus.ch"

User Function Ed552()
    Local aLayers := {{"ModelDef","Rules and data"},{"ViewDef","UI"},{"MenuDef","Actions"}}
    Local nI
    // Responsibility map; no MVC routine is activated.
    For nI := 1 To Len(aLayers)
        ConOut(aLayers[nI,1]+" -> "+aLayers[nI,2])
    Next
Return Nil
Expected result

Prints three responsibility rows. Under review: editorial example neither compiled nor run in Protheus. Check includes, release, RDD and context before testing.

BEST PRACTICES
  • Keep model/view IDs consistent, separate validation from persistence and review action permissions. For User Function entry points, follow the official model-ID naming rule rather than reusing the function name blindly.
  • Under review: editorial example neither compiled nor run in Protheus. Check includes, release, RDD and context before testing.

Related content

REFERENCES
  1. TOTVS. MPFormModel. TDN. Accessed on 2026-10-27.
  2. TOTVS. FWFormModel. TDN. Accessed on 2026-10-27.
  3. TOTVS. FWFormView. TDN. Accessed on 2026-10-27.
  4. Atilio. zMVCMd1.prw, exemplo comunitário completo; commit 7d275a7. Accessed on 2026-10-27.
Status
Under review
Page created on
Last reviewed on
Original language
Portuguese
Reviewed by
Usina.BR
0 approved comment(s)

Comments

There are no approved comments yet.

Sign in with Google or Microsoft to comment.

Powered by Usina Docs · Alpha