When working with Uniface applications, understanding how to properly exit components is crucial for building robust and maintainable software. Today, I'll walk you through everything you need to know about the exit statement in Uniface 10.4! π
This article was created with the assistance of AI and is based on the official Uniface Documentation 10.4.
π What is the Exit Statement?
The exit statement is a powerful control flow mechanism that immediately exits the current component instance and returns to either the previous component or a specified instance. Think of it as your "emergency escape hatch" from any component! π
β¨ Basic Syntax
exit {Expression} {, InstanceName}
π― Quick Example
exit (0), "MAINMENU"
π§ Parameters Breakdown
| Parameter | Data Type | Description |
|---|---|---|
| Expression | Number | Numeric expression that gets placed in $status. If omitted, defaults to 0 π |
| InstanceName | String | Target component instance name (max 32 characters) π |
β‘ Key Features and Behavior
πββοΈ Immediate Exit
The exit statement doesn't mess around - it immediately terminates the current component and bypasses:
- π Data validation
- π« Remaining triggers
- β
loseFocustrigger in Form components
π§Ή Automatic Cleanup
Before exiting, Uniface automatically handles cleanup:
- ποΈ Removes child instances
- π§ Executes
CLEANUPoperations if they exist - πΎ Performs implicit
deleteinstancefor local components
π» Practical Examples
π€ Simple Exit with Status
trigger accept
$1 = CUSTNAME
exit (1)
end; accept
π― Exit to Named Instance
trigger quit
askmess "Return to Main Menu?"
if ($status = 1) ; if answer is "Y"
exit (0), "MAINMENU"
else
return (-1)
endif
end; quit
β οΈ Important Considerations
π¨ Service Component Restrictions
- β Not allowed in self-contained Service and Report components
- π Use
returnstatement for remote synchronous services - π‘ Avoid in remote asynchronous services
π‘οΈ Exception Handling
Be careful when using exit inside try-finally-endtry blocks! The finally block won't execute if exit deletes the current instance. Place cleanup logic before the exit statement instead. π
π― Best Practices
- π¨ Use parentheses for better readability:
exit (0) - π Validate instance names before using them
- π§Ό Implement CLEANUP operations for proper resource management
- βοΈ Choose wisely between
exitandreturnbased on your needs
π Conclusion
The exit statement is an essential tool in your Uniface toolkit. When used correctly, it provides clean and efficient component navigation while maintaining proper resource management. Remember to consider the implications on triggers and cleanup operations when implementing exit logic in your applications! π―
Happy coding! π¨βπ»β¨
Top comments (0)