Usina BRAdvPL Guide
Sign in
← All topics
PRACTICAL GUIDEUnder review

Single-entity MVC

MPFormModel():New(); AddFields(); SetPrimaryKey()

Defines a model for one dictionary table.

Single-entity MVCAdvPL
01 · OVERVIEW

Overview

One entity is represented by a Field submodel created with AddFields. FWFormStruct(1,alias) supplies Model metadata; type 2 supplies View metadata. The community sample uses SBM, while this adaptation uses fictitious ZZ1 keyed by ZZ1_FILIAL+ZZ1_COD. The helper is a ModelDef sketch, not a complete application: it needs prepared SX2/SX3 and integration with ViewDef and actions. The demonstration does not invoke the block. (Sources: refs. 1–5.)

02 · SYNTAX

Syntax

MPFormModel():New(); AddFields(); SetPrimaryKey()
03 · PRACTICAL EXAMPLE

Commented example

#Include "Protheus.ch"
#Include "FWMVCDef.ch"

User Function Ed553()
    // Requires test dictionary ZZ1.
    Local bBuild := {|| BuildModel()}
    ConOut(ValType(bBuild))
Return Nil

Static Function BuildModel()
    Local oModel := MPFormModel():New("ED553M")
    Local oStruct := FWFormStruct(1,"ZZ1")
    oModel:AddFields("ZZ1MASTER",Nil,oStruct)
    oModel:SetPrimaryKey({"ZZ1_FILIAL","ZZ1_COD"})
Return oModel
Expected result

Prints B; the helper is not evaluated and creates/writes no tables. Under review: editorial example neither compiled nor run in Protheus. Check includes, release, RDD and context before testing.

BEST PRACTICES
  • Verify field types/widths, primary key, relation and actual index before activation. Test validation, cancellation and persistence separately; the View must bind the correct submodel IDs.
  • 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. TOTVS. FWFormStruct. TDN. Accessed on 2026-10-27.
  5. Atilio. zMVCMd1.prw; 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