1

I am displaying a messageDlg confirmation screen with Yes and No buttons. Reversing the buttons in the code has no affect.

 answer := messageDlg('Are you sure?', mtConfirmation, [mbYes, mbNO], 0);

Is there a way to change the default option to No without creating a custom dialog such as demonstrated here What is the best way in Delphi to show customized Message Dialogs?

Jsk
  • 159
  • 1
  • 13
  • "*Reversing the buttons in the code has no affect*" - the `Buttons` parameter is a `Set` of `TMsgDlgBtn` flags. The order in which flags are assigned to a `Set` is irrelevant. Each flag has a designated bit in the `Set`. A `Set` can be queried for which bits have been set, but not in which order they were set. – Remy Lebeau Apr 30 '20 at 16:44
  • Neither has it an effect, nor does it affect. – AmigoJack Apr 30 '20 at 20:40

1 Answers1

5

The MessageDlg function already supports specifying the default button:

MessageDlg('Are you sure?', mtConfirmation, [mbYes, mbNo], 0, mbNo);
                                                              ^^^^

(Reversing the order of mbYes and mbNo couldn't possibly have any effect, since [mbYes, mbNo] is a set, and sets have no order.)

Andreas Rejbrand
  • 105,602
  • 8
  • 282
  • 384
  • 4
    (Hint: You could have discovered this yourself if you had pressed F1 with the caret inside the `MessageDlg` function name in the IDE. That will open the function's documentation.) – Andreas Rejbrand Apr 30 '20 at 15:34
  • 2
    I am relatively new to Delphi and was using the [Delphi Basics](http://www.delphibasics.co.uk/RTL.asp?Name=messagedlg) website which has served me well so far. I guess I will have to cross reference more sources in future. – Jsk Apr 30 '20 at 15:44
  • 2
    @Jsk: Fair enough. But IMHO, the official documentation should *always* be the first and primary source when you use any API or other system or product. (In this case, the Embarcadero docs.) – Andreas Rejbrand Apr 30 '20 at 16:05
  • 2
    @Jsk The Delphi Basics site is horribly out-dated, there are a LOT of modern functionalities missing from it. Case in point, it only shows 1 version of `MessageDlg()`, but there are actually [2 versions](http://docwiki.embarcadero.com/Libraries/en/Vcl.Dialogs.MessageDlg) available. `MessageDlgPos()` is a better example of the descrepency between [what Delphi Basics shows](http://www.delphibasics.co.uk/RTL.asp?Name=MessageDlgPos) (1 version) and [what Embarcadero's DocWiki shows](http://docwiki.embarcadero.com/Libraries/en/Vcl.Dialogs.MessageDlgPos) (4 versions). – Remy Lebeau Apr 30 '20 at 16:50
  • Why all the Delphi Basics bashing? Delphi Basics is more concise, contains all the information on one screen, including code examples. No need to click to multiple pages to get all the answers like the Embarcadero DocWiki. – Michael Riley - AKA Gunny Apr 30 '20 at 17:46
  • 1
    @MichaelRiley-AKAGunny: For the reasons that have already been pointed out. Delphi Basics is horribly outdated, contains partial or incorrect information, and isn't maintained and updated to keep up with new language or RTL features and enhancements. You don't *get all the answers* on a single page; you get partial or invalid information on that page. If you choose to get your information from that kind of source, you're missing out on a lot of things that any current Delphi coder should know. – Ken White Apr 30 '20 at 18:18