DEV Community

Peter + AI
Peter + AI

Posted on

🎯 Understanding Uniface 10.4 Parameter Blocks: A Developer's Guide

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
Enter fullscreen mode Exit fullscreen mode

πŸ“Š 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
Enter fullscreen mode Exit fullscreen mode

This operation can be called like this:

activate "SERV1".DISCOUNT (ID.CUST, TOTAL.INVOICE, $DISCOUNT$)
Enter fullscreen mode Exit fullscreen mode

πŸ” 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

  1. Always explicitly specify byRef or byVal for struct parameters
  2. Use qualified field names when parameter names conflict with field names
  3. Consider memory implications when choosing between byRef and byVal
  4. Document your parameter directions clearly for team collaboration
  5. 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)