?
Solved

MessageDlg with a DefaultButton ?

Posted on 2003-03-17
7
Medium Priority
?
1,685 Views
Last Modified: 2009-12-16
Hi Folks,

I don't know what is wrong, but my memory seems to be troubling me.  I need to display a message dialog with a mbYes, mbNo, and mbYesToAll button.  So I use the MessageDlg function for that, which is perfect.  But somehow this function always uses the mbYes as the default button, and of course I need the mbNo button to be the default one.  I thought this was possible, that there was an overloaded function in which you could pass the DefaultButton, but apparently I am wrong.

Does anyone have a simple solution for this ?


Regards,
0
Comment
Question by:Stefaan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
7 Comments
 
LVL 27

Expert Comment

by:kretzschmar
ID: 8151122
you could use the windows.messagebox
( also the buttons may than in a localized language)

like

  if windows.MessageBox( self.Handle
                       , 'AText'
                       , 'ACaption'
                       , mb_iconwarning or
                         mb_yesnocancel or
                         mb_defbutton2)  = mryes then  //default by NO

meikl ;-)
0
 
LVL 6

Accepted Solution

by:
DaFox earned 200 total points
ID: 8151138
Hi Stefaan.

You can't do this with a MessageDlg, Borland forgot about that ;-). The problem is that they don't use the standard Windows dialog boxes (they're using their own dialog instead).

You have to do it with MessageBox instead (or CreateMessageDlg; see below)

Here's a nice example made by Peter Below:

{+------------------------------------------------------------
 | Function DefMessageDlg
 |
 | Parameters:
 |  aCaption: Caption to use for the dialog. If empty the
 |            default is used.
 |  Msg     : message to display
 |  Dlgtype : type of dialog, see MessageDlg online help
 |  Buttons : buttons to display, see MessageDlg online help
 |  Defbutton: ModalResult of the button that should be the
 |             default.
 |  HelpCtx:  help context (optional)
 | Returns:
 |  ModalResult of the dialog
 | Description:
 |  This is a wrapper around CreateMessageDialog, basically
 |  an extension of the MessageDlg VCL function that allows
 |  us to modify the caption and determine which button will
 |  be the default.
 | Error Conditions:
 |  none
 |
 |Created: 07.06.98 14:54:20 by P. Below
 +------------------------------------------------------------}
Function DefMessageDlg(const aCaption: String;
                       const Msg: string;
                       DlgType: TMsgDlgType;
                       Buttons: TMsgDlgButtons;
                       DefButton: Integer;
                       HelpCtx: Longint): Integer;
Var
  i: Integer;
  btn: TButton;
Begin
  With CreateMessageDialog(Msg, DlgType, Buttons) Do
  try
    If Length(aCaption) > 0 Then
      Caption := aCaption;
    HelpContext := HelpCtx;
    For i := 0 To ComponentCount-1 Do Begin
      If Components[i] Is TButton Then Begin
        btn := TButton(Components[i]);
        btn.Default:= btn.ModalResult = DefButton;
        If btn.Default Then
          ActiveControl := Btn;
      End;
    End; { For }
    Result := ShowModal;
  finally
    Free;
  end;
End;


Markus
0
 
LVL 6

Expert Comment

by:DaFox
ID: 8151155
Argh!

May I quote Madshi?
"I won't get meikl, anyway, he's just too fast for me...   :-)"

;-)

Markus
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 27

Expert Comment

by:kretzschmar
ID: 8151201
:-)))

ah, dafox,
I'm really silent the last days,
don't be frustrated, my quickness
is only randomly

btw. you gave a nice alternative

meikl ;-)
0
 
LVL 3

Author Comment

by:Stefaan
ID: 8151216
Exactly what I was searching for.  And I knew Borland had somthing like this, but apparently thats in the CLX from delphi 7 ( QDialogs unit ).

Thanks for the help.,
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 8151454
you see, dafox, quickness is not all :-))
0
 
LVL 6

Expert Comment

by:DaFox
ID: 8151479
Yep, "Gut' Ding will Weile haben" ;-)

Markus
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question