📝 This blog post was created with AI assistance to help explain Uniface concepts in simple terms.
🎯 What is $curkey?
The $curkey function in Uniface 10.4 is a helpful tool that tells you which key triggered your validation code. Think of it as a way to identify "which key am I currently working with?" when your validation runs.
📊 What Does $curkey Return?
When you call $curkey, it gives you back one of these values:
- 1 - This means you're working with the primary key 🗝️
- Numbers > 1 - These are candidate key numbers (like key #2, #3, etc.) 🔢
- Empty string "" - Something went wrong ❌
⚠️ Important Rules
You can only use $curkey in two specific places:
-
validateKeytrigger -
leaveModifiedKeytrigger
📌 Note: You cannot use it in self-contained Reports!
💡 Practical Example
Here's how you might use $curkey in real code:
trigger validateKey
selectcase $curkey
case 1
; This runs for primary key validation 🗝️
; Add your primary key checks here
case 2
; This runs for candidate key #2 validation 🔑
; Add specific validation for key #2
case 4
; This runs for candidate key #4 validation 🔑
; Add specific validation for key #4
elsecase
; Handle errors 🚨
message "Error %%$procerror occurred at %%$procerrorcontext"
message "Context: %%$dataerrorcontext"
endselectcase
end; validateKey
🔍 Why Use $curkey?
Different keys might need different validation rules. For example:
- Your primary key might need to check for duplicates 🔍
- A secondary key might need format validation 📝
- Another key might need business rule checks 📋
With $curkey, you can write one trigger that handles all these different cases smartly! 🎯
🚀 Quick Tips
- Always use
selectcasewith$curkeyfor clean code organization 📚 - Include an
elsecasefor error handling 🛡️ - Remember to check
$procerrorif$curkeyreturns empty 🔧
🎉 Conclusion
The $curkey function is a simple but powerful tool in Uniface 10.4. It helps you write smarter validation code by letting you know exactly which key triggered your validation logic. This makes your code more organized and easier to maintain! 💪
Happy coding with Uniface! 👨💻👩💻
Top comments (0)