Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Defualt to "no" on a MessageDlg 1

Status
Not open for further replies.

tbarone

Programmer
Aug 1, 2001
13
0
0
US
I Have a simple yes/no Message Dlg Box, but I want it to default to "no" instead of "yes?

MessageDlg('Would you like to print a reciept?',
mtConfirmation, [mbYes, mbNo], 0);
 
Try this:
Code:
function TForm1.MyMessageDlg(const ACaption: string;
  const Msg: string;
  DlgType: TMsgDlgType;
  Buttons: TMsgDlgButtons;
  DefButton: Integer;
  HelpCtx: Longint): Integer;
var
  i: Integer;
  button: TButton;
begin
  with CreateMessageDialog(Msg, DlgType, Buttons) do
    try
      Caption := ACaption;
      HelpContext := HelpCtx;
      for i := 0 to ComponentCount - 1 do
      begin
        if (Components[i] is TButton) then
        begin
          button := TButton(Components[i]);
          button.default := button.ModalResult = DefButton;
          if button.default then
            ActiveControl := button;
        end;
      end;
      Result := ShowModal;
    finally
      Free;
    end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  if MyMessageDlg('Message Title', 'Message Content',
    mtConfirmation, [mbYes] + [mbNo], mrNo, 0) = mrYes then
    ShowMessage('Yes clicked!');
end;

Hope this helps [flip]
 
There is another method of doing:

Eexample:
if MessageBox(ProgressStatusForm.Handle, pchar('Message content'), 'Message Title',MB_YESNO + MB_ICONQUESTION + MB_DEFBUTTON2) = IDYES then
........


Cheers!
 
Nice one FamWS! Works just as well and all in one statement too!!! Have a star! :-Q
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top