Usina BRAdvPL Guide
Sign in
← All topics
PRACTICAL GUIDEUnder review

Code blocks with parameters and Eval

Executes a parameterized expression and explicitly uses its result.

Code blocks with parameters and EvalAdvPL
01 · OVERVIEW

Overview

A block uses { |parameters| expressions } and receives values supplied to Eval after the block itself. Its return is the last evaluated expression; an empty block returns Nil. Parameters are local to the block; capturing a caller variable is a different binding with memory and context-lifetime implications. The example only adds two numbers without executing text as a macro. In UI or ASort callbacks, follow the calling component’s arguments and required return type. (TOTVS, n.d., refs. 1–2)

Return value

No single return value: this is a composite workflow.

03 · PRACTICAL EXAMPLE

Commented example

#Include "Protheus.ch"
User Function EdBloco()
    Local bAdd := {|nOne, nTwo| nOne + nTwo}
    Local nTotal := Eval(bAdd, 7, 3)
    // Creating the block does not execute its expression.
    ConOut(cValToChar(nTotal))
Return Nil
Expected result

Expected result: 10. Under review: editorial example neither compiled nor run in Protheus. Check includes, release, RDD and context before testing.

BEST PRACTICES
  • Keep blocks short. Validate types at the caller contract and avoid retaining callbacks indefinitely or evaluating untrusted text.
  • Under review: editorial example neither compiled nor run in Protheus. Check includes, release, RDD and context before testing.

Related content

REFERENCES
  1. TOTVS. Blocos de Código. TDN. Accessed on 2026-10-26.
  2. TOTVS. Eval. TDN. Accessed on 2026-10-26.
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