DEV Community

Peter + AI
Peter + AI

Posted on

πŸ“ Understanding Uniface's putmess Statement: A Developer's Guide

When working with Uniface applications, effective message handling is crucial for providing user feedback and debugging information. Today, I'll walk you through one of Uniface's essential statements: putmess. πŸš€

🎯 What is putmess?

The putmess statement is a built-in Uniface function that appends text to the message frame. It's a simple yet powerful tool for displaying information to users or logging messages during application execution.

πŸ“‹ Basic Syntax

putmess {MessageText}
Enter fullscreen mode Exit fullscreen mode

πŸ’‘ Simple Example

putmess "Export complete."
Enter fullscreen mode Exit fullscreen mode

πŸ”§ Parameters and Return Values

Parameters:

  • MessageText (String): The message content you want to display. If you omit this parameter, an empty line is added to the message frame.

Return Values: None

βš™οΈ Usage Guidelines

The putmess statement can be used in all component types except:

  • Dynamic Server Pages
  • Static Server Pages

Important Note: The statement is ignored in a receiveMessage trigger if the user is currently in the message frame when the trigger activates.

πŸ–₯️ Batch Mode Behavior

In batch mode, putmess writes messages directly to the screen or batch log file, depending on your operating system settings. This makes it particularly useful for background processing and automated tasks.

πŸ“Š Practical Example: Error Handling with putmess

Here's a real-world example showing how to use putmess for error handling and user feedback:

operation exec
    CUSTNAME.CUSTOMER = $1
    COUNTRY.CUSTOMER = $2
    retrieve
    if ($status < 0)
        putmess "Retrieve problem. No printout."
        apexit ; end application
    else
        print "SALESLASER","A"
        putmess "Printout sent to LaserJet II"
    endif
end; exec
Enter fullscreen mode Exit fullscreen mode

In this example:

  • πŸ” We attempt to retrieve customer data
  • ❌ If the retrieval fails ($status < 0), we display an error message
  • βœ… If successful, we print the data and confirm the action

πŸ’Ž Pro Tips

  • 🎨 Use putmess for progress indicators in long-running operations
  • πŸ› Combine with the Uniface Debugger to dump message frame contents to files
  • πŸ“± Remember that message frame contents are accessible via the $putmess function
  • πŸ”„ Messages accumulate in the frame - they don't replace previous content

🎁 Conclusion

The putmess statement is a fundamental tool in Uniface development that enhances user experience through clear communication. Whether you're building error handling, progress tracking, or simple notifications, mastering putmess will make your applications more user-friendly and debuggable.

This article is based on the official Uniface 10.4 documentation and was created with assistance from AI to help fellow developers understand this essential Uniface feature better. πŸ€–

Top comments (0)