DEV Community

Peter + AI
Peter + AI

Posted on

🧹 Mastering Uniface's Clear Statement: A Complete Guide

πŸ“‹ What is the Clear Statement?

The clear statement in Uniface is a powerful tool for clearing data from components or entities. Whether you're refreshing data after updates or cleaning up invalid entries, understanding how to use clear effectively is essential for every Uniface developer! πŸš€

πŸ”§ Syntax and Usage

Basic Syntax

clear{/e Entity}
Enter fullscreen mode Exit fullscreen mode

Key Parameters

Parameter Type Description
Entity String Entity to be cleared. Can be a string, field, variable, function, or parameter that evaluates to an entity name.

βš™οΈ Qualifiers

/e - Clears data from the specified entity rather than the entire component

πŸ“Š Return Values

$status Values

  • 0 βœ… - Data was successfully cleared, or no entities are painted on the component
  • -3 ❌ - Exceptional I/O error (hardware or software)
  • -16 🌐 - Network error: unknown

$procerror Values

  • -2 through -12 - Database I/O errors
  • -16 through -30 - Network I/O errors
  • -1102 - Invalid entity name or entity not painted on component

πŸ’‘ Practical Examples

Example 1: Clearing Invalid Data

trigger leaveModified 
 if ((salary > 100000) & (job != "PRESIDENT"))
 message "Salary not valid"
 clear/e "entity"
 endif
end; leaveModified
Enter fullscreen mode Exit fullscreen mode

Example 2: Refreshing Data After Updates

trigger detail
; save foreign key for occurrences displayed in entity C
; set up foreign key, ready for retrieve
; retrieve new data entered on service Z
 $1 = FOREIGN_KEY.C
 activate "Z".EXEC($1)
 clear/e "C"
 FOREIGN_KEY.C = $1
 retrieve/e "C"
end
Enter fullscreen mode Exit fullscreen mode

⚠️ Important Considerations

🚫 Never Use in These Triggers

CAUTION: Never use the clear/e statement in the getFocus or startModification triggers. This can cause Uniface to enter an infinite loop!

🎯 Record Component Behavior

Use clear/e with care on components with Record behavior. A Record component has only one outermost entity, and clearing the first outermost entity will clear data from all entities painted on the component.

πŸ”„ When to Use Clear

  • πŸ”„ When data has been added in a different component and needs to be redisplayed
  • 🧹 To clean up invalid user entries
  • πŸ“Š To refresh data after external updates
  • 🎯 To reset the active path for components

πŸŽ‰ Key Takeaways

  • ✨ clear without parameters clears all component data
  • 🎯 clear/e "Entity" clears specific entity data
  • πŸ’Ύ Database data remains unaffected - only display data is cleared
  • πŸ”’ Locked occurrences remain locked after clearing
  • πŸ›£οΈ The active path for the component is reset

Understanding the clear statement is crucial for effective Uniface development. Use it wisely to maintain clean, responsive applications! πŸš€


πŸ“š This guide is based on the official Uniface 10.4 documentation and was created with AI assistance to help fellow developers master this essential Uniface feature.

Top comments (0)