DEV Community

Peter + AI
Peter + AI

Posted on

Understanding Uniface 10.4's $display Function πŸ“±

This blog post was created with AI assistance to help developers understand Uniface better.

Hey developers! πŸ‘‹ Today we're diving into one of Uniface 10.4's built-in functions that might seem simple but can be quite useful: the $display function.

What Does $display Do? πŸ€”

The $display function is straightforward - it returns the name of the current display device translation table being used by your Uniface application. Think of it as a way to ask your application: "Hey, what display setup are you currently using?"

How to Use It πŸ’»

Using $display is super simple. Here's the basic syntax:

vDdt = $display
Enter fullscreen mode Exit fullscreen mode

That's it! The function takes no parameters and returns a string containing the device translation table name.

Real-World Example 🌟

Here's a practical example of how you might use this function:

; Check what display device we're using
string vCurrentDisplay
vCurrentDisplay = $display

; Log it for debugging
putmess "Current display device: %%vCurrentDisplay%%"

; Maybe adjust behavior based on display type
if (vCurrentDisplay = "MOBILE_DISPLAY")
    ; Do mobile-specific stuff
    call "MOBILE_LAYOUT"
else
    ; Use desktop layout
    call "DESKTOP_LAYOUT"
endif
Enter fullscreen mode Exit fullscreen mode

When Should You Use This? 🎯

The $display function becomes handy when you need to:

  • Debug display issues - Know exactly which translation table is active
  • Create adaptive UIs - Adjust your interface based on the display type
  • Log system information - Include display info in your application logs
  • Handle multiple display configurations - When your app supports different devices

Important Things to Remember ⚠️

Keep these points in mind when using $display:

  • Batch mode limitation - This function won't work in batch mode (you'll get error -33)
  • Works everywhere else - You can use it in all component types except batch
  • Returns a string - The result is always text, so treat it as such

Error Handling πŸ› οΈ

Always check for errors when using system functions. Here's how:

string vDisplayName
vDisplayName = $display

; Check if there was an error
if ($procerror != 0)
    if ($procerror = -33)
        putmess "Cannot use $display in batch mode"
    else
        putmess "Error getting display info: %%$procerror%%"
    endif
else
    putmess "Display device: %%vDisplayName%%"
endif
Enter fullscreen mode Exit fullscreen mode

Wrapping Up πŸŽ‰

The $display function might seem basic, but it's a useful tool in your Uniface toolkit. Whether you're debugging display issues, creating responsive applications, or just need to know what display configuration is active, this function has got you covered!

Remember to always handle the batch mode limitation and check for errors. Happy coding with Uniface 10.4! πŸš€

Have questions about Uniface development? Feel free to ask in the comments below! πŸ’¬

Top comments (0)