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)