Building Dynamic User Alerts with TAdvSmartMessageBox Modern desktop applications require non-intrusive ways to communicate with users. The traditional modal dialog box, which blocks workflow and demands an immediate click, is increasingly replaced by fluid, asynchronous notifications.
For Delphi and C++Builder developers using the TMS VCL UI Pack, TAdvSmartMessageBox offers a highly customizable, modern solution for displaying dynamic user alerts. This component allows you to show sleek, toast-like notifications that automatically fade, stack, and embed interactive elements without freezing your application’s main thread.
Here is how to get started and maximize the potential of TAdvSmartMessageBox in your VCL applications. Understanding the Core Architecture
Unlike standard message boxes, TAdvSmartMessageBox operates as a notification manager. It handles a queue of individual alert items, managing their positions on the screen, their animation states, and their lifespans. Key features include:
Non-modal execution: Alerts display smoothly while the user continues working.
Automatic stacking: Multiple alerts stack vertically or horizontally without overlapping.
HTML formatting: Text properties support mini-HTML tags for bolding, colors, and hyperlinks.
Actionable elements: Buttons and checkboxes can be embedded directly into the alert. Step 1: Basic Configuration
To begin, drop a TAdvSmartMessageBox component onto your main form. You can configure its global appearance using the Object Inspector, or define them dynamically in code.
procedure TMainForm.ConfigureMessageBox; begin // Position the alerts in the bottom-right corner of the screen AdvSmartMessageBox1.Position := mpBottomRight; // Set global animation behavior AdvSmartMessageBox1.Animate := true; AdvSmartMessageBox1.AnimateTime := 300; // in milliseconds // Allow messages to automatically close after a delay AdvSmartMessageBox1.AutoClose := true; AdvSmartMessageBox1.DisplayTime := 5000; // Show for 5 seconds end; Use code with caution. Step 2: Displaying a Simple Alert
Showing a quick notification requires minimal code. Use the ShowMessage method to push a new alert onto the screen.
procedure TMainForm.BtnSimpleAlertClick(Sender: TObject); begin AdvSmartMessageBox1.ShowMessage( ‘File Export Complete’, ‘Your report has been successfully saved to the Documents folder.’, msgInformation ); end; Use code with caution.
The third parameter accepts standard message types (e.g., msgInformation, msgWarning, msgError), which automatically handle the icon styling for the alert. Step 3: Crafting Dynamic, Rich-Text Content
Because TAdvSmartMessageBox supports mini-HTML rendering, you can dynamically inject formatting, variables, and links directly into your alert text. This keeps notifications highly readable and context-aware.
procedure TMainForm.BtnDynamicAlertClick(Sender: TObject); var UserName: string; ItemCount: Integer; begin UserName := ‘Alex’; ItemCount := 7; AdvSmartMessageBox1.ShowMessage( ‘Sync Status’, Format(‘Hello %s, you have %d pending updates waiting for review.’, [UserName, ItemCount]), msgWarning ); end; Use code with caution. Step 4: Adding Buttons and Handling User Interaction
Dynamic alerts are most powerful when users can react to them. TAdvSmartMessageBox allows you to add custom buttons to individual messages. You can catch the user’s response asynchronously using the OnMessageClick or OnMessageButtonClick events. Pushing an Alert with Buttons:
procedure TMainForm.BtnInteractiveAlertClick(Sender: TObject); var MsgItem: TSmartMessageBoxItem; begin // Create a base message AdvSmartMessageBox1.ShowMessage( ‘Update Available’, ‘A new software version is ready.’, msgConfirmation ); // Retrieve the newly added item to customize it MsgItem := AdvSmartMessageBox1.Messages[AdvSmartMessageBox1.Messages.Count - 1]; // Add interactive options MsgItem.Buttons.Add(‘Install Now’); MsgItem.Buttons.Add(‘Remind Me Later’); // Prevent auto-closing so the user has time to choose MsgItem.AutoClose := False; end; Use code with caution. Handling the Callback Event:
Implement the OnMessageButtonClick event handler on your component to manage the user’s choice:
procedure TMainForm.AdvSmartMessageBox1MessageButtonClick(Sender: TObject; Item: TSmartMessageBoxItem; ButtonIndex: Integer); begin case ButtonIndex of 0: StartUpdateProcess(); // “Install Now” clicked 1: ScheduleReminder(); // “Remind Me Later” clicked end; // Manually close the item since AutoClose was disabled Item.Close; end; Use code with caution. Best Practices for Smart Notifications
To ensure your dynamic alerts enhance user experience rather than disrupt it, keep these principles in mind:
Use AutoClose Judiciously: Use automatic fading for low-priority logs (e.g., “Changes Saved”). For critical errors or actionable prompts, disable AutoClose so information isn’t lost.
Limit Concurrent Messages: Too many stacked alerts overwhelm users. Use the AdvSmartMessageBox1.Messages.Count property to check the queue size before spinning up new alerts.
Keep Text Concise: Desktop toast notifications should be scannable. Use bold HTML tags to highlight key metrics or actions, keeping descriptions under two sentences.
By shifting from rigid modal dialogs to TAdvSmartMessageBox, your Delphi applications gain a polished, professional notification architecture that mirrors modern web and OS-level user experiences.
To help refine this implementation for your specific project, tell me:
What version of Delphi or C++Builder and TMS VCL UI Pack are you targeting?
Do you need your alerts to include custom branding, styles, or dark mode support?
Leave a Reply