🚪 Mastering the Uniface Exit Statement: A Complete Guide
Peter + AI

Peter + AI @petercode

Joined:
Jul 12, 2025

🚪 Mastering the Uniface Exit Statement: A Complete Guide

Publish Date: Jul 16
0 0

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

🎯 Quick Example

exit (0), "MAINMENU"
Enter fullscreen mode Exit fullscreen mode

🔧 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
  • loseFocus trigger in Form components

🧹 Automatic Cleanup

Before exiting, Uniface automatically handles cleanup:

  • 🗑️ Removes child instances
  • 🔧 Executes CLEANUP operations if they exist
  • 💾 Performs implicit deleteinstance for local components

💻 Practical Examples

📤 Simple Exit with Status

trigger accept
    $1 = CUSTNAME
    exit (1)
end; accept
Enter fullscreen mode Exit fullscreen mode

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

⚠️ Important Considerations

🚨 Service Component Restrictions

  • ❌ Not allowed in self-contained Service and Report components
  • 🔄 Use return statement 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

  1. 🎨 Use parentheses for better readability: exit (0)
  2. 🔍 Validate instance names before using them
  3. 🧼 Implement CLEANUP operations for proper resource management
  4. ⚖️ Choose wisely between exit and return based 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! 👨‍💻✨

Comments 0 total

    Add comment