Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Change default button in MessageDlg

1,159 views
Skip to first unread message

Ahn Nuzen

unread,
Jun 11, 1998, 3:00:00 AM6/11/98
to

Hi Folks,

How do I force the default button selection in the MessageDlg function?
The Yes button is selected by default in the below statement How do I
change it to No button?

if MessageDlg('I want no to be selected', mtInformation, [mbNo, mbYes],
0) = mrNO then
exit;

Many thanks,

Ahn.


Kurt Barthelmess (TeamB)

unread,
Jun 12, 1998, 3:00:00 AM6/12/98
to

Ahn -

You do not. There is no option for that. If you want an alternate
button, see the API under MessageBoix or MessageBoxEx.

Good luck.

Kurt

Jean Ferreira

unread,
Jun 12, 1998, 3:00:00 AM6/12/98
to

Ahn Nuzen,

Use CreateMessageDialog instead. Example:

procedure x;
var
I: Integer;
begin
with CreateMessageDialog('This is a Test', mtInformation, mbYesNoCancel)
do
try
for I:=0 to ControlCount - 1 do
if Controls[I].Name = 'Cancel' then TButton(Control[I]).Default :=
True;
finally
Free;
end;
end;

Bye

Jean Ferreira

Ahn Nuzen wrote in message
<35802093...@nojunkmail.workhorse.trandes.com>...

Peter Below

unread,
Jun 12, 1998, 3:00:00 AM6/12/98
to

> How do I force the default button selection in the MessageDlg function?
> The Yes button is selected by default in the below statement How do I
> change it to No button?
>
> if MessageDlg('I want no to be selected', mtInformation, [mbNo, mbYes],
> 0) = mrNO then
> exit;
>
Ahn

use this custom function instead of MessageDlg:

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
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;

procedure TForm1.Button2Click(Sender: TObject);
begin
If DefMessageDlg( 'Please confirm',
'Do you want to format your harddisk now?',
mtConfirmation,
mbYesNoCancel,
mrno,
0 ) = mrYes
Then
ShowMessage('Formatting disk...');
end;


Peter Below (TeamB) 10011...@compuserve.com)


0 new messages