This blog post was created with AI assistance to help developers understand Uniface Global ProcScripts better. π€
π What are Global ProcScripts?
Global ProcScripts are reusable code modules in Uniface that live in a runtime library. Think of them as shared functions that you can call from anywhere in your application. Instead of writing the same code multiple times in different components, you write it once as a Global ProcScript and call it whenever you need it.
The main benefit is code reusability and better organization. When you need to update the logic, you only change it in one place rather than hunting through dozens of components.
π οΈ How to Create a Global ProcScript Library
Creating Global ProcScripts in Uniface 10.4 is straightforward. First, you need a project to work with. Here's the step-by-step process:
Step 1: Open Your Project
In the U-Bar, click Browse, select prj, then choose your project. If you don't have a project yet, you'll need to create one first.
Step 2: Create the Library
Go to the Templates tab in the Resource Browser and find the Global ProcScript Library template. Drag and drop it onto your project in the Structure Editor. Give it a meaningful name like "MyGlobalLibrary" and add a description.
Step 3: Add Your ProcScript
Double-click the library to open it. You'll see the Define Structure worksheet. Drag the Empty ProcScript template from the UPALETTE_LIBPRC palette onto your library object. Rename it to something descriptive like "Multiply" or "CalculateTax".
Step 4: Write Your Code
Switch to the Write Script worksheet. Select your Global ProcScript object and start coding. Here's a simple example that multiplies two numbers:
entry Multiply
params
numeric par1 : IN
numeric par2 : IN
numeric result : OUT
endparams
result = par1 * par2
return(0)
end
Step 5: Compile
Click the Compile button to compile your library and all its contents. Make sure there are no errors before moving on.
π Calling Your Global ProcScript
Once your Global ProcScript is compiled, you can call it from any component using the call command. The syntax is simple:
call LibraryName::ProcScriptName(arguments)
Here's a real example:
variables
numeric num1
numeric num2
numeric answer
endvariables
num1 = 5
num2 = 10
call MYPRCS::Multiply(num1, num2, answer)
; Now answer contains 50
message "Result: %%answer%%"
If you don't specify a library name, Uniface searches in this order: the component library, the application shell library, and finally SYSTEM_LIBRARY.
β οΈ Common Problems and Solutions
Problem 1: Function Not Found Error
If you get error -1109, Uniface can't find your Global ProcScript. Check these things:
- Is the library name spelled correctly?
- Is the ProcScript name spelled correctly?
- Did you compile the library after making changes?
- Is the library deployed to the correct location?
Problem 2: Wrong Number of Arguments
Error -1122 means you're passing the wrong number of parameters. Make sure your call statement has the same number of arguments as defined in the params block of your Global ProcScript.
Problem 3: Parameter Type Mismatch
Error -1113 indicates invalid parameters. While Uniface tries to automatically convert data types, it doesn't always work. Make sure you're passing compatible types (for example, don't pass a string when a numeric is expected).
Problem 4: Namespace Conflicts
If you have multiple Global ProcScripts with the same name in different libraries, Uniface might call the wrong one. Always specify the library name explicitly using the LibraryName:: prefix to avoid confusion.
π‘ Best Practices
- Use descriptive names for your libraries and ProcScripts
- Document your parameters clearly in the code
- Keep each ProcScript focused on one specific task
- Test your Global ProcScripts thoroughly before deploying
- Use error handling to check the $status variable after calling
π― Conclusion
Global ProcScripts are a powerful feature in Uniface 10.4 that help you write cleaner, more maintainable code. By centralizing reusable logic in libraries, you save time and reduce bugs. Start small with simple helper functions, and as you get comfortable, you can build more complex shared modules.
Happy coding! π
Top comments (0)