DEV Community

Peter + AI
Peter + AI

Posted on

๐Ÿ”ง Mastering Uniface's delitem Statement: Your Guide to List Management

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
Enter fullscreen mode Exit fullscreen mode

๐Ÿ” 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
Enter fullscreen mode Exit fullscreen mode

๐Ÿท๏ธ 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
Enter fullscreen mode Exit fullscreen mode

๐Ÿ”„ 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"
Enter fullscreen mode Exit fullscreen mode

๐Ÿš€ 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 /id is case-insensitive by default - use /case when 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)