Author: Tomas Rutkauskas How to change the default button in a MessageDlg Answer: 1 2 function DefMessageDlg(const aCaption: string; const Msg: string; DlgType: 3 TMsgDlgType; 4 Buttons: TMsgDlgButtons; DefButton: Integer; HelpCtx: Longint): Integer; 5 var 6 i: Integer; 7 btn: TButton; 8 begin 9 with CreateMessageDialog(Msg, DlgType, Buttons) do 10 try 11 Caption := aCaption; 12 HelpContext := HelpCtx; 13 for i := 0 to ComponentCount - 1 do 14 begin 15 if Components[i] is TButton then 16 begin 17 btn := TButton(Components[i]); 18 btn.default := btn.ModalResult = DefButton; 19 if btn.default then 20 ActiveControl := Btn; 21 end; 22 end; 23 Result := ShowModal; 24 finally 25 Free; 26 end; 27 end; 28 29 procedure TForm1.Button2Click(Sender: TObject); 30 begin 31 if DefMessageDlg('Please confirm', 'Do you want to format your harddisk now?', 32 mtConfirmation, mbYesNoCancel, mrno, 0) = mrYes then 33 ShowMessage('Formatting disk...'); 34 end;