DEV Community

Peter + AI
Peter + AI

Posted on

๐Ÿ” Understanding the $syntax Function in Uniface 10.4

Note: This blog post was created with the assistance of AI technology.

If you work with Uniface 10.4, you might have come across the $syntax function. This powerful tool helps you match text patterns in your applications. Let me show you how it works in simple terms! ๐Ÿ’ก

๐Ÿ“ What Does $syntax Do?

The $syntax function converts a regular string into a special pattern string. Think of it like creating a template that other strings can match against. This is super useful when you need to check if user input follows a specific format.

Basic Structure

$syntax(String, SyntaxMode)
Enter fullscreen mode Exit fullscreen mode
  • String: The text you want to convert
  • SyntaxMode: How the matching should work (optional)

๐ŸŽฏ Syntax Modes Explained

Uniface offers four different modes to control how pattern matching works:

1. Classic Mode (Default) ๐Ÿ”ง

This mode treats special characters like #, *, &, @ as pattern codes.

$syntax("D&G")
Enter fullscreen mode Exit fullscreen mode

This creates the pattern '%[X]D&G' which matches DOG, DIG, DUG, etc. The & acts as a wildcard for any single character!

2. CaseSensitive Mode ๐Ÿ” 

Perfect when exact case matters! Special characters are treated as normal text.

$syntax("D&G", "CS")
Enter fullscreen mode Exit fullscreen mode

This only matches the exact string "D&G" with the same uppercase letters.

3. CaseInsensitive Mode ๐Ÿ”ก

Ignores uppercase and lowercase differences. Great for user-friendly searches!

$syntax("D&G", "CI")
Enter fullscreen mode Exit fullscreen mode

This matches D&G, d&g, D&g, or any combination of upper and lowercase.

4. NlsLocale Mode ๐ŸŒ

Handles special characters from different languages according to locale settings.

$syntax("i#B", "NlsLocale")
Enter fullscreen mode Exit fullscreen mode

In Turkish locale, this correctly handles the dotted and dotless "i" characters!

๐Ÿ’ผ Real-World Example

Imagine you need to check if a customer name matches a pattern:

if (NAME1 = $syntax("D&G", "CaseInsensitive"))
    ; Name matches the pattern
    message "Name matches!"
else
    ; Name doesn't match
    message "Name doesn't match."
endif
Enter fullscreen mode Exit fullscreen mode

This checks if the NAME1 field contains text matching the pattern, ignoring case differences.

โš ๏ธ Important Things to Remember

  • The pattern must appear within the first 256 characters of the string you're checking
  • If something goes wrong, $syntax returns an empty string
  • Check $procerror for error details (value -1013 means invalid syntax string)
  • You can use this function in all Uniface component types

๐ŸŽ“ When Should You Use $syntax?

Here are some practical scenarios:

  • Form Validation: Check if user input matches required formats
  • Search Features: Create flexible search that ignores case
  • Data Filtering: Find records matching specific patterns
  • International Apps: Handle text with special characters correctly

๐Ÿš€ Pro Tips

  1. Start Simple: Use "Classic" mode first to understand pattern codes
  2. Test Thoroughly: Different modes behave very differently
  3. Handle Errors: Always check $procerror after using $syntax
  4. Choose the Right Mode: Match the mode to your business requirements

โœจ Conclusion

The $syntax function is a powerful tool in your Uniface toolkit. Whether you need exact matching, case-insensitive searches, or international character support, there's a mode for your needs. Start experimenting with simple patterns and gradually work your way up to more complex scenarios! ๐ŸŽ‰

Happy coding! ๐Ÿ‘จโ€๐Ÿ’ป๐Ÿ‘ฉโ€๐Ÿ’ป

Top comments (0)