🚀 Mastering Uniface ProcScript Functions: A Complete Guide
Peter + AI

Peter + AI @petercode

Joined:
Jul 12, 2025

🚀 Mastering Uniface ProcScript Functions: A Complete Guide

Publish Date: Jul 18
0 0

If you're working with Uniface development, understanding ProcScript functions is crucial for writing clean, modular code. In this comprehensive guide, we'll explore everything you need to know about declaring and using functions in Uniface ProcScript! 💡

This article is based on the official Uniface Documentation 10.4 and was crafted with AI assistance to provide you with the most accurate and up-to-date information.

🔧 What Are ProcScript Functions?

ProcScript functions are reusable script modules that can be invoked from other modules within their vicinity. Think of them as building blocks that help you organize your code and avoid repetition. They're essential for creating maintainable Uniface applications! ⚡

📝 Basic Function Syntax

Here's the fundamental structure of a Uniface ProcScript function:

function FunctionName
{returns DataType}
{params
...
endparams}
{variables
...
endvariables}
... Proc statements and precompiler directives
{return (Expression) }
end
Enter fullscreen mode Exit fullscreen mode

🎯 Key Components:

  • FunctionName: Maximum 32 bytes, can contain letters (A-Z), digits (0-9), or underscores (_)
  • returns DataType: Optional - specifies the return data type
  • params/endparams: Optional - defines function parameters
  • variables/endvariables: Optional - declares local variables
  • return: Optional - returns a value from the function

🌐 Function Visibility and Scope

Understanding where your functions can be called from is crucial! The visibility depends on where you declare them:

📍 Declaration Location 🔍 Visibility Scope
Field's code container Other modules at the field level
Entity's code container Entity level + entity's fields
Component code container Entire component (all entities and fields)
Global ProcScript Same Global ProcScript + other ProcScript modules within it

📞 Calling Functions: Two Ways to Do It

Uniface gives you flexibility in how you call functions! Here are both methods:

🎪 Method 1: Direct Function Call

function doSomething
 returns string
 return("I did something")
end

; Call as function:
vResult = doSomething()
; vResult = "I did something"
; $status = 0
Enter fullscreen mode Exit fullscreen mode

🎪 Method 2: Using Call Statement

; Call using call statement:
call doSomething
; $status = 0
; Return value is not captured inline
Enter fullscreen mode Exit fullscreen mode

💼 Real-World Examples

🏪 Example 1: Store Trigger with Function

trigger store
call LSTORE
end; store

; Component-level Script container
function LSTORE
 store
 if ($status < 0)
 message "Store error!"
 rollback
 else
 message "Store done."
 commit
 endif
end
Enter fullscreen mode Exit fullscreen mode

🧮 Example 2: Mathematical Function with Parameters

TOTAL = multiply(FLD1, FLD2)

; Component-level Script container
function multiply
returns numeric
params
 numeric parm1 : IN
 numeric parm2 : IN
endparams
variables
 numeric multiplyResult
endvariables
multiplyResult = parm1 * parm2
return multiplyResult
end ; multiply
Enter fullscreen mode Exit fullscreen mode

🎯 Best Practices and Tips

  • 🔒 Function names: Keep them descriptive and within the 32-byte limit
  • 📦 Return values: Use typed returns for better code clarity
  • 🏗️ Scope planning: Declare functions at the appropriate level for your needs
  • 🔄 Global ProcScripts: Place explicit functions at the end of other code
  • ⚠️ Module declarations: Always end preceding modules with explicit end statements

🎉 Wrapping Up

Uniface ProcScript functions are powerful tools for creating modular, maintainable code. By understanding their syntax, scope, and calling conventions, you can write more efficient and organized Uniface applications. Remember to leverage the flexibility of both direct function calls and call statements based on your specific needs! 🚀

Happy coding! 💻✨

Comments 0 total

    Add comment