DEV Community

Peter + AI
Peter + AI

Posted on

πŸš€ Understanding Uniface 10.4 $editmode Function: Complete Developer Guide

This blog post was created with AI assistance to help developers understand this essential Uniface feature. πŸ€–

πŸ“š What is the $editmode Function?

The $editmode function in Uniface 10.4 is a powerful built-in function that controls how users can interact with data on form components. Think of it as a security guard that decides what level of access users have to your application's data! πŸ›‘οΈ

This function is essential for creating user-friendly applications where different users might need different levels of access to the same forms.

🎯 The Three Access Modes

The $editmode function works with three distinct values, each providing different levels of user access:

Mode 0: Edit Mode πŸ“

Full access power! Users can retrieve, view, and modify all data. This is your standard editing environment where users have complete control over the form data.

Mode 1: Query Mode πŸ”

Search and filter only! Users can enter search criteria and profile data, but they cannot modify any retrieved values. Perfect for creating search interfaces or when you want users to find data without changing it.

Mode 2: Display Mode πŸ‘€

Read-only experience! Users can only view data - no modifications allowed whatsoever. This is ideal for creating reports or confirmation screens.

βš™οΈ Basic Syntax

Using $editmode is straightforward. You can both read the current mode and set a new one:


; Reading the current mode
currentMode = $editmode

; Setting a new mode
$editmode = 0  ; Edit mode
$editmode = 1  ; Query mode  
$editmode = 2  ; Display mode
Enter fullscreen mode Exit fullscreen mode

πŸ’‘ Practical Examples

Example 1: Checking Current Mode

Here's how to inform users about their current access level:


operation exec
selectcase $editmode
 case 0
 message/info "This form is editable" 
elsecase
 message/info "This form is not editable"
 endselectcase
edit
end; exec
Enter fullscreen mode Exit fullscreen mode

Example 2: Starting in Display Mode

Sometimes you want to open a form in read-only mode from the beginning:


operation displayCustomer
; Start display mode for this form
 $editmode = 2 ; DISPLAY
 edit/modal
end
Enter fullscreen mode Exit fullscreen mode

Example 3: Switching Modes Dynamically

After saving data, you might want to prevent further changes:


operation doStore
 ; Store the data and prevent more changes
 store
 ; TODO: Add error handling here...
 $editmode = 2 ; Switch to DISPLAY mode
end
Enter fullscreen mode Exit fullscreen mode

πŸ”§ How Uniface Determines Initial Mode

Uniface automatically sets the initial $editmode value based on how your form was activated:

  • Edit Mode (0): Set when forms are started with activate or newinstance statements under normal editing conditions
  • Query Mode (1): Set when forms are started with newinstance using the QUERY=TRUE property
  • Display Mode (2): Set when forms are started with newinstance using DISPLAY=TRUE or activated with a display statement

πŸŽͺ Key Terms for Beginners

  • Form Component: A user interface element in Uniface that displays data and allows user interaction
  • ProcScript: Uniface's programming language (a 4GL - Fourth Generation Language)
  • 4GL: High-level programming language that requires less coding than traditional languages
  • Operation: A code block in Uniface that performs specific tasks

🚨 Common Pitfalls to Avoid

Forgetting Error Handling

Always include proper error handling when storing data before switching modes. Users need feedback if something goes wrong!

Not Informing Users

Make sure users understand what mode they're in. A confused user is an unhappy user! Consider adding visual indicators or messages.

Hardcoding Mode Values

Instead of using magic numbers, consider defining constants:


; Better approach - use meaningful constants
variables
  numeric EDIT_MODE = 0
  numeric QUERY_MODE = 1  
  numeric DISPLAY_MODE = 2
endvariables

$editmode = DISPLAY_MODE  ; Much clearer!
Enter fullscreen mode Exit fullscreen mode

🎯 Best Practices

  1. Always check permissions: Verify user access rights before allowing mode changes
  2. Provide user feedback: Let users know when modes change and why
  3. Use consistent patterns: Apply the same mode-switching logic across your application
  4. Document your usage: Comment your code to explain why you're changing modes

πŸŽ‰ Conclusion

The $editmode function is a fundamental tool for controlling user interaction in Uniface applications. By mastering these three simple modes, you can create more secure, user-friendly applications that adapt to different user needs and scenarios.

Remember: Good user experience design means giving users exactly the right level of access they need - no more, no less! 🎯

Start experimenting with $editmode in your next Uniface project and see how it can improve your application's usability and security! πŸš€

Top comments (0)