DEV Community

Peter + AI
Peter + AI

Posted on

πŸš€ Uniface apstart: Passing Control to the Component Manager

πŸ“‹ Introduction

As a Uniface developer, you'll encounter the apstart statement sooner or later. In this post, I'll explain what it's all about and how it's used in practice.

This post was created with the help of AI and is based on Uniface documentation 10.4.

🎯 What is apstart?

The apstart statement is a central component of Uniface applications. It passes control of the application to the component manager and waits for user input.

πŸ”§ Basic Properties

  • Only allowed in the apStart trigger of application shells
  • Required in the apStart trigger of Uniface Server startup shells
  • Optional in other application types (since newer versions)

πŸ“Š Return Values

The apstart statement returns various values in $status:

Value Meaning
-1 An error occurred (details in $procerror)
Other value Return value of the last component/operation

⚠️ Common Error Codes

Error Code Constant Meaning
1402 <UPROCERR_STATEMENT> Statement not allowed in this trigger

πŸ—οΈ Practical Usage

Typical Use Case

trigger apStart
    ; Start non-modal forms
    activate "FORM1"
    activate "FORM2"
    activate "FORM3"

    ; Pass control to user
    apstart
end; apStart
Enter fullscreen mode Exit fullscreen mode

πŸ›‘οΈ Exception Handling

For robust applications, you should use exception handling:

trigger apStart
    try
        ; Your initialization logic here
        activate "MAIN_FORM"
        apstart
    catch
        ; Error handling
        message "Error starting the application"
    end
end; apStart
Enter fullscreen mode Exit fullscreen mode

🎨 Special Properties

πŸ”„ Automatic Detection

Uniface automatically detects the activation of a sequence of non-modal forms and automatically passes control to the user after the last activate.

πŸ’₯ Application Termination

⚠️ Important: If no forms are present in the component pool when apstart is executed, the application terminates.

🎯 Best Practices

  1. Always use in apStart trigger
  2. Implement exception handling
  3. Activate at least one form before apstart
  4. No -1 return from components (risk of confusion with errors)

πŸ“ Conclusion

The apstart statement is a fundamental element for Uniface applications. It enables the clean transfer of control to the component manager and is essential for developing interactive applications.

This post is based on Uniface documentation 10.4 and was created with AI support. For further details, consult the official Uniface documentation.

Top comments (0)