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
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
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)