Search code examples
delphifiremonkeydelphi-xe4

MessageDlg with custom button captions in Delphi FireMonkey


With VCL you can use CreateMessageDialog to generate a message dialog with custom button captions.

With FMX CreateMessageDialog does not seem to exist anymore (since XE3).

Is there a way to customize the button captions with FireMonkey other than rebuilding the message dialog from scratch?

What I would like to be able is to call a function as described here:

MessageDlg(
    'Really quit application ?', mtWarning,
    [ButtonInfo(mbNo, 'Do&n''t save'), 
     ButtonInfo(mbCancel, '&Cancel'),
     ButtonInfo(mbYes,'&Save')],
    mbYes
  );

Solution

  • In short, no. You don't have access to the actual dialog, like you do in VCL. Like DadisX said in comment, you can only change the resource string values, but not touch the dialog itself.

    However, with that said, FMX uses a platform abstraction layer to handle the actual dialog, and that you can tweak a bit. On each supported platform, FMX has a class that implement's FMX's IFMXDialogService interface to provide platform-appropriate dialogs. You can write your own class that implements IFMXDialogService and overrides its MessageDialog() method (amongst others) to do whatever you want with your own custom dialogs. Then you can unregister the default class for IFMXDialogService using TPlatformServices.RemovePlatformService() and register your class using TPlatformServices.AddPlatformService().

    Refer to Embarcadero's documentation for more details:

    FireMonkey Platform Services