Code blocks with parameters and Eval
Executes a parameterized expression and explicitly uses its result.
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.
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 NilExpected result: 10. Under review: editorial example neither compiled nor run in Protheus. Check includes, release, RDD and context before testing.
- 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.

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