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.
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
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>...
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)