DEV Community

Peter + AI
Peter + AI

Posted on

πŸ“ Mastering File Selection in Uniface 10.4: The Complete filebox Guide

File selection dialogs are a fundamental part of modern application development, and Uniface 10.4 provides a powerful filebox statement that makes implementing file selection seamless and platform-native. Whether you're building enterprise applications or desktop tools, understanding how to effectively use filebox can significantly enhance your user experience. πŸš€

This article is based on the official Uniface Documentation 10.4, with AI assistance helping to structure and present the information in a developer-friendly format.

🎯 What is filebox?

The filebox statement in Uniface displays a native GUI file selection dialog that automatically adapts to your platform. It's incredibly versatile, supporting both file and folder selection, with robust filtering capabilities and intelligent default behavior.

Basic Syntax

filebox{/save | /dir | /savenocheck} {Filter {, DefaultDirectory} }
Enter fullscreen mode Exit fullscreen mode

πŸ”§ Key Features and Qualifiers

/save - Create New Files

Perfect for save dialogs where users need to specify a new filename:

filebox/save "*.txt", "C:/Documents/"
Enter fullscreen mode Exit fullscreen mode

/savenocheck - Silent Overwrite

When you need to overwrite files without confirmation prompts:

filebox/savenocheck "*.log", "C:/temp/"
Enter fullscreen mode Exit fullscreen mode

/dir - Folder Selection

Switches the dialog to folder selection mode:

filebox/dir
Enter fullscreen mode Exit fullscreen mode

⚠️ Note: You cannot combine /dir with /save or use filters when selecting directories.

🎨 Advanced Filtering Techniques

Single File Type

filebox "*.xml"
Enter fullscreen mode Exit fullscreen mode

Multiple File Types (Windows)

filebox "*.png;*.gif;*.jpg", "D:/images/"
Enter fullscreen mode Exit fullscreen mode

Filter with Description

filebox "*.json=JSON Files", "D:/work/uniface/"
Enter fullscreen mode Exit fullscreen mode

πŸ“Š Return Values and Error Handling

Understanding filebox return values is crucial for robust applications:

$status Value Description
< 0 Error occurred (check $procerror)
0 User cancelled selection
1 File selected successfully ($result contains path)

Example Error Handling

filebox "*.dat", "C:/data/"
if ($status = 1)
    ; File selected successfully
    message "Selected: ", $result
elseif ($status = 0)
    ; User cancelled
    message "Selection cancelled"
else
    ; Error occurred
    message "Error: ", $procerror
endif
Enter fullscreen mode Exit fullscreen mode

πŸ’‘ Pro Tips and Best Practices

πŸ”„ Platform Compatibility

Always ensure your directory paths end with the appropriate separator:

  • Windows: "C:/temp/"
  • Unix/Linux: "/tmp/"

🎭 Character Mode Fallback

In character mode environments, filebox automatically provides a text-based alternative, ensuring your applications work everywhere.

🌐 Customizing Dialog Text

You can customize the dialog text by editing Uniface message text 4805 for better localization and user experience.

πŸ” Real-World Examples

Image File Selector

; Select image files with preview-friendly formats
filebox "*.png;*.gif;*.jpg;*.bmp=Image Files", "D:/images/"
Enter fullscreen mode Exit fullscreen mode

Export File Dialog

; Save export files with automatic extension
filebox/save "*.exp;*.xml=Export Files", "C:/exports/"
Enter fullscreen mode Exit fullscreen mode

Configuration Directory Picker

; Let users choose configuration directory
filebox/dir
Enter fullscreen mode Exit fullscreen mode

πŸŽ‰ Conclusion

The Uniface filebox statement is a powerful tool that simplifies file selection while maintaining platform consistency. Its flexibility in handling different file types, directories, and error conditions makes it indispensable for modern Uniface applications. πŸ’ͺ

Whether you're building data import features, configuration managers, or document processors, mastering filebox will significantly improve your application's usability and professional appearance.

Have you used filebox in your Uniface projects? Share your experiences and tips in the comments below! πŸ‘‡

Top comments (0)