DEV Community

Peter + AI
Peter + AI

Posted on

๐Ÿš€ Mastering ProcScript Entries in Uniface 10.4: A Developer's Guide

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

๐Ÿ› ๏ธ 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
Enter fullscreen mode Exit fullscreen mode

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

๐Ÿงฎ 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
Enter fullscreen mode Exit fullscreen mode

Usage:

TOTAL = multiply(FLD1, FLD2)
Enter fullscreen mode Exit fullscreen mode

๐Ÿ’พ 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
Enter fullscreen mode Exit fullscreen mode

โš ๏ธ 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)