Working with Uniface can be challenging, especially when it comes to understanding parameter declarations. Let's dive deep into the params...endparams
block and explore how to effectively use parameter definitions in your Uniface 10.4 applications! π
This article is based on the official Uniface Documentation 10.4, and AI assistance helped me structure this comprehensive guide.
π What is the params Block?
The params...endparams
block is fundamental in Uniface development. It defines formal parameters for:
- π§ Operations
- βοΈ Functions (global or local ProcScript modules)
- π Global ProcScripts
π οΈ Basic Syntax Structure
params
DataType ParamName : Direction
{DataType} Field.Entity{.Model} : Direction
{DataType} $ComponentVariable$ : Direction
{byRef} | {byVal} struct ParamName : Direction
entity Entity{.Model} : Direction
occurrence Entity{.Model} : Direction
xmlstream [DTD:DTDName]ParamName : Direction
endparams
π Key Parameter Elements
Element | Description | Example |
---|---|---|
DataType | Uniface data type (string, numeric, etc.) |
string , numeric
|
ParamName | Max 32 bytes, letters, digits, underscores |
CUSTID , AMOUNT_TOTAL
|
Direction | Parameter flow direction |
IN , OUT , INOUT
|
π― Parameter Directions Explained
π₯ IN Parameters
Input only - data flows from caller to operation
π€ OUT Parameters
Output only - data flows from operation back to caller. Warning: Initial value is unpredictable! β οΈ
π INOUT Parameters
Bidirectional - data flows both ways
ποΈ Special Parameter Types
π¦ Struct Parameters
Structs can be passed by reference (byRef
) or by value (byVal
):
- byRef: Only memory pointer is passed - faster but same process required
- byVal: Complete data copy - slower but works across processes
ποΈ Entity and Occurrence Parameters
These are "constructed parameters" that transfer entity data between components:
- entity: Transfers ALL occurrences of an entity π
- occurrence: Transfers only the CURRENT occurrence π
π XML Stream Parameters
Handle XML data with optional DTD validation using xmlstream
parameters.
π‘ Practical Example
Here's a real-world example of a discount calculation operation:
operation DISCOUNT
params
string CUSTID : IN
numeric AMOUNT : INOUT
numeric PERCENTAGE : OUT
endparams
; Calculate discount based on customer
PERCENTAGE = 0
if ( CUSTID == "ufbv" ) PERCENTAGE = 20
if ( CUSTID == "acme" ) PERCENTAGE = 15
AMOUNT = AMOUNT * ( 100 - PERCENTAGE) / 100
end
This operation can be called like this:
activate "SERV1".DISCOUNT (ID.CUST, TOTAL.INVOICE, $DISCOUNT$)
π Important Limitations and Rules
- π Maximum 64 parameters per operation
- πΎ Maximum parameter size: 10 MB
- π« Constructed parameters can't be used in functions
- β οΈ Avoid OUT/INOUT parameters with asynchronous activation
- π Cross-process byRef struct parameters will cause errors
π― Parameter Scope Rules
Understanding scope is crucial:
- Component-level: Entity, occurrence, field, and component variable parameters π
- Operation-level: Named parameters exist only within their operation/module π
- Name conflicts: Parameters take precedence over fields with the same name π₯
π Best Practices
- Always explicitly specify
byRef
orbyVal
for struct parameters - Use qualified field names when parameter names conflict with field names
- Consider memory implications when choosing between byRef and byVal
- Document your parameter directions clearly for team collaboration
- Test cross-process scenarios thoroughly when using struct parameters
π Conclusion
Mastering Uniface parameter blocks is essential for building robust, maintainable applications. The flexibility of different parameter types and directions gives you powerful tools for component communication, but with great power comes great responsibility! πͺ
Happy coding with Uniface 10.4! π
Top comments (0)