This blog post was created with AI assistance to help developers understand Uniface 10.4 message functionality better. π€
π― What Are Messages in Uniface?
Messages in Uniface 10.4 are named text blocks that you can reuse throughout your application. Think of them as containers for text that you want to display in labels, user notifications, or help texts. The best part? You can easily create multilingual applications by defining the same message in different languages! π
π Opening the Message Editor
Getting started with messages is straightforward:
- Navigate to More Editors and select Messages
- Choose a Message Library where you want to store your messages (or create a new one)
- The message editor opens and you're ready to create your first message! β¨
βοΈ Creating Your First Message
Creating a message is simple and intuitive:
- Click the New button in the message editor
- Enter a unique Message Name (each message needs a unique identifier)
- Select the Language for your message
- Add an optional Description to help you remember what the message is for
- Type your text in the Text field (up to 512 bytes)
- Set the Severity level if needed (info, warning, error)
Important note: Message names must be unique and cannot use the same name as a help text! β οΈ
π» Using Messages in ProcScript
Once you've created your messages, you can use them in your code with two helpful functions:
The $text Function
The $text
function retrieves the text content of your message. Here's how it works:
vLabelText = $text(WELCOME_MESSAGE)
This retrieves the text from a message named WELCOME_MESSAGE
and stores it in the variable vLabelText
. Notice that you don't need quotation marks around the message name! π
The $textexist Function
Before using a message, you might want to check if it exists. That's where $textexist
comes in handy:
if ($textexist(CUSTOM_MESSAGE))
vText = $text(CUSTOM_MESSAGE)
else
vText = "Default text"
endif
This prevents errors by checking if the message exists before trying to retrieve it. Smart and safe! π‘οΈ
π·οΈ Using Messages as Labels
One of the most powerful features is using messages as labels in your user interface. Here are two common approaches:
Static Label Text
You can set a label directly using the $text
function:
$text(BUTTON_LABEL)
Remember: no quotation marks around the message name!
Dynamic Field Values
You can also fill fields with message text at runtime, typically in the exec operation:
trigger exec
TITLE_FIELD.MYENTITY = $text(PAGE_TITLE)
INFO_FIELD.MYENTITY = $text(INFO_TEXT)
end; exec
This approach is perfect for displaying static information that might change based on language or configuration. π
π¨ Practical Example: Multilingual Welcome Message
Let's say you're building an application that needs to greet users in different languages. Here's how you would set it up:
- Create a message named
WELCOME_MSG
in English: "Welcome to our application!" - Create the same message name
WELCOME_MSG
in German: "Willkommen in unserer Anwendung!" - In your code, simply use:
trigger exec
GREETING.MYFORM = $text(WELCOME_MSG)
end; exec
Uniface automatically displays the correct language based on the user's language settings. No complex logic needed! π
π‘ Best Practices
- Use descriptive names: Choose message names that clearly indicate their purpose (e.g.,
ERROR_LOGIN_FAILED
instead ofMSG1
) - Check before you use: Always use
$textexist
before$text
when working with dynamic message names - Organize with libraries: Group related messages in the same message library for better organization
- Keep it concise: Remember the 512-byte limit for message text
- Be careful when deleting: Message libraries can contain not just messages, but also help texts and language setups. Double-check before deleting! π¨
π Saving Your Work
Don't forget to save your messages! You have two options:
- Choose File > Save to save your changes
- Click OK to save all messages and close the editor
π― Conclusion
Messages in Uniface 10.4 are a powerful tool for creating maintainable, multilingual applications. By centralizing your text content in message libraries, you make it easy to update text, support multiple languages, and keep your code clean. The $text
and $textexist
functions give you flexible control over how and when you display messages to your users.
Start using messages in your next Uniface project and experience the benefits of centralized text management! Happy coding! π¨βπ»π©βπ»
Top comments (0)