Hey developers! ๐ Today we're diving deep into one of Uniface's essential list manipulation commands - the delitem statement. Whether you're working with indexed or associative lists, this powerful command will help you manage your data structures efficiently.
๐ Note: This article was created with the assistance of AI and is based on the official Uniface 10.4 documentation.
๐ฏ What is delitem?
The delitem statement in Uniface 10.4 is your go-to tool for removing items from lists. It's versatile, supporting both indexed and associative lists, and can be used across all component types.
๐ Basic Syntax
There are two main ways to use delitem:
delitem List, N // For indexed lists
delitem/id{/case} List, Index // For associative lists
๐ Qualifiers Explained
| Qualifier | Description |
|---|---|
/id |
Delete item with specific value from associative list |
/case |
Enable case-sensitive matching (use with /id) |
๐ Parameters & Return Values
Parameters:
- List (String): The Uniface list to modify
- N (Number): Item position in indexed list (1-based)
- Index (String): Value to find in associative list
Return Values ($status):
- 0: No item was deleted
- >0: Item number of the deleted item
๐ก Practical Examples
๐ข Working with Indexed Lists
// Delete the 3rd item from an indexed list
$valrep(DBMSFLD) = "mss;ora;syb;db2"
; ValRep is "mss;ora;syb;db2"
delitem $valrep(DBMSFLD), 3
; ValRep is now "mss;ora;db2"
// Delete the last item using -1
delitem $valrep(DBMSFLD), -1
; Removes the last item from the list
๐ท๏ธ Working with Associative Lists
// Case-insensitive deletion (default)
$valrep(DATEFLD) = "mon=monday;tue=tuesday;wed=wednesday"
delitem/id $valrep(DATEFLD), "TUE"
; ValRep is now "mon=monday;wed=wednesday"
// Case-sensitive deletion
delitem/id/case $list$, "ab"
; Only deletes items with exact case match
๐ Treating Indexed Lists as Associative
// Same list, different approach
$valrep(DBMSFLD) = "mss;ora;syb;db2"
delitem/id $valrep(DBMSFLD), "syb"
; ValRep is now "mss;ora;db2"
๐ Pro Tips
- ๐งน Clear entire list: Use
$1 = ""instead of deleting items one by one - โก Performance: For large lists, consider the trade-offs between indexed and associative approaches
- ๐ Case sensitivity: Remember that
/idis case-insensitive by default - use/casewhen needed - ๐ Item numbering: Uniface uses 1-based indexing, not 0-based
๐ฏ When to Use delitem
The delitem statement is perfect for:
- ๐ง Dynamic list management in user interfaces
- ๐ Removing selected items from dropdown lists
- ๐๏ธ Cleaning up data structures during processing
- โ๏ธ Implementing custom list manipulation logic
๐ Wrapping Up
The delitem statement is a fundamental tool in the Uniface developer's toolkit. Its flexibility with both indexed and associative lists makes it invaluable for dynamic data management. Remember to check the $status return value to ensure your deletions were successful!
Happy coding! ๐๐ป
Want to learn more about Uniface? Check out the official documentation and keep exploring this powerful development platform!
Top comments (0)