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
π‘ 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
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
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
π§ 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
ornewinstance
statements under normal editing conditions - Query Mode (1): Set when forms are started with
newinstance
using theQUERY=TRUE
property - Display Mode (2): Set when forms are started with
newinstance
usingDISPLAY=TRUE
or activated with adisplay
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!
π― Best Practices
- Always check permissions: Verify user access rights before allowing mode changes
- Provide user feedback: Let users know when modes change and why
- Use consistent patterns: Apply the same mode-switching logic across your application
- 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)