DEV Community

Peter + AI
Peter + AI

Posted on

🎯 Understanding ProcScript Statement Effects in Uniface 10.4

This blog post was created with AI assistance to help explain Uniface concepts in simple terms.

πŸ“š What This Article Covers

If you work with Uniface 10.4, you've probably used ProcScript statements like clear/e. But did you know that these statements behave differently depending on how your component entities are related? Let's explore this important concept! πŸ”

πŸ€” The Problem

When you paint multiple entities on a component instance, the way ProcScript statements affect your component depends on whether these entities are related or unrelated to each other.

βœ… Scenario 1: Related Entities (Expected Behavior)

When you have only related entities painted on your component, things work as you'd expect. Here's what happens:

  • You execute clear/e on the outermost entity 🧹
  • All related entities get cleared
  • The instance modification flag ($instancemod) is set to 0 ✨
  • The database origin flag ($instancedb) is set to 0 ✨

πŸ’‘ Example with Related Entities

Imagine you have a Customer entity with a related Order entity painted on your form. When you run clear/e on Customer:

clear/e $Customer
; Result: Both Customer and Order are cleared
; $instancemod = 0
; $instancedb = 0
Enter fullscreen mode Exit fullscreen mode

This makes sense! All the data is gone, so there are no modifications and nothing comes from the database anymore. πŸ‘

⚠️ Scenario 2: Unrelated Entities (Surprising Behavior)

Now here's where it gets tricky! When you have unrelated entities on the same component, the behavior changes:

  • You execute clear/e on one outermost entity 🧹
  • Only that entity and its related entities get cleared
  • The flags are set only for the specified entity ⚑
  • Unrelated entities are NOT affected 🚫
  • $instancemod and $instancedb might NOT be 0 ❗

πŸ’‘ Example with Unrelated Entities

Imagine you have a Customer entity and a completely separate Product entity (not related) on the same form. When you run clear/e on Customer:

clear/e $Customer
; Result: Only Customer (and its related entities) are cleared
; Product entity remains unchanged!
; $instancemod = depends on Product's status
; $instancedb = depends on Product's status
Enter fullscreen mode Exit fullscreen mode

The Product entity still has its data, so the instance-level flags reflect the combined status of ALL entities on the component! 🎭

πŸŽ“ Key Takeaway

The value of instance-level functions like $instancemod and $instancedb depends on all entities painted on your component, not just the one you're working with. This is especially important to remember when you have unrelated entities!

πŸ“ Best Practices

  • Be aware of entity relationships when designing your components πŸ—οΈ
  • Check instance-level flags carefully when dealing with multiple entities πŸ”Ž
  • Consider component design - sometimes separate components work better than unrelated entities on one component 🎨
  • Test your ProcScript with different entity configurations to understand the behavior πŸ§ͺ

πŸ”— Related ProcScript Elements

  • clear - Statement to clear entity data
  • $instancedb - Flag showing database origin
  • $instancemod - Flag showing modification status

πŸŽ‰ Conclusion

Understanding how ProcScript statements interact with related and unrelated entities is crucial for building robust Uniface applications. By keeping these principles in mind, you can avoid unexpected behavior and write more predictable code! πŸš€

Happy coding! πŸ’»βœ¨

Top comments (0)