Hey fellow developers! ๐ Today I want to share insights about ProcScript entries in Uniface - a powerful feature that can significantly improve your code organization and reusability. This article is based on the Uniface Documentation 10.4, and I had some assistance from AI to structure this content.
๐ What are ProcScript Entries?
ProcScript entries are essentially script modules that can be invoked from within the same component. Think of them as private functions with component-level visibility that help you organize your code better.
๐ Basic Syntax
Here's the fundamental structure of a ProcScript entry:
entry EntryName
{returns DataType}
{params
...
endparams}
{variables
...
endvariables}
... Proc statements and precompiler directives
{return (Expression) }
end
๐ ๏ธ Key Features and Rules
โ Entry Names
- Maximum length: 32 bytes
- Allowed characters: Letters (A-Z), digits (0-9), underscores (_)
- Must be declared in the same component where it's called
๐ Return Values
- Entry statement doesn't affect
$status
- Return values work differently based on how you call the entry:
- Inline invocation: Returns the actual value
- Call statement: Returns value in
$status
(integers only)
๐ฏ Practical Examples
๐ Example 1: Simple Entry with Return Value
entry doSomething
returns string
return("I did something")
end
You can call this entry in two ways:
// As a function
vResult = doSomething()
// vResult = "I did something"
// $status = 0
// Using call statement
call doSomething
// $status = 0
๐งฎ Example 2: Entry with Parameters
entry multiply
returns numeric
params
numeric parm1 : IN
numeric parm2 : IN
endparams
variables
numeric multiplyResult
endvariables
multiplyResult = parm1 * parm2
return multiplyResult
end
Usage:
TOTAL = multiply(FLD1, FLD2)
๐พ Example 3: Database Operations
trigger store
call LSTORE
end
entry LSTORE
store
if ($status < 0)
message "Store error!"
rollback
else
message "Store done."
commit
endif
end
โ ๏ธ Important Considerations
๐ Entry Precedence
- All entries in a component are treated as component-level, regardless of where they're defined
- Field-level entries can overwrite component-level entries with the same name
- Component entries take precedence over inherited model entries
- Last defined entry wins if multiple entries have the same name
๐ Global ProcScript Entries
- Have global scope - can be called from any application component
- Explicitly-defined entries must be placed at the end of the global ProcScript
- Otherwise, main global ProcScript code gets ignored
๐ก Best Practices
- ๐ง Use functions instead of entries when possible - The documentation recommends this to avoid precedence issues
- ๐ Use the Compiled Modules Inspector in Uniface IDE to track entry definitions
- ๐ฏ Keep entries focused on single responsibilities
- ๐ Document your entries well, especially their parameters and return values
๐ Conclusion
ProcScript entries are a powerful tool for organizing your Uniface code and creating reusable modules. While they're incredibly useful, remember to be mindful of their scoping rules and consider using functions when appropriate.
Happy coding! ๐
This article is based on the Uniface Documentation 10.4. Have questions or want to share your own Uniface experiences? Drop a comment below!
Top comments (0)