Showing posts with label MessageDlg with cancel focus. Show all posts
Showing posts with label MessageDlg with cancel focus. Show all posts

Tuesday, August 14, 2018

Delphi Message Dialog with cancel button focus on defualt


Var
    ButtonNames: array[TMsgDlgBtn] of string = ('Yes', 'No', 'OK', 'Cancel', 'Abort', 'Retry', 'Ignore', 'All', 'NoToAll', 'YesToAll', 'Help');


function MessageDlgWithFocus(const Msg: string; DlgType: TMsgDlgType;
                                    Buttons: TMsgDlgButtons; FocusBtn: TMsgDlgBtn;
                                    HelpCtx: Longint): Integer;
var Btn: TComponent;
begin
  with CreateMessageDialog(Msg, DlgType, Buttons) do
  begin
    try
      HelpContext := HelpCtx;
      Position := poScreenCenter;

      Btn := FindComponent( ButtonNames[FocusBtn] );
      if (Btn <> nil) and (Btn is TWinControl) then
      ActiveControl := Btn as TWinControl;

      Result := ShowModal;
    finally
      Free;
    end;
  end;
end;



If MessageDlgWithFocus('The confirmation message dialog with cancel button focus on default', mtConfirmation, [mbOk, mbCancel], mbCancel, 0) = mrOk Then
    Do your stuffs ....

Delphi Thread Example

Delphi Thread Example Threads mean a lot with the latest computer technology. They allow you to perform multiple tasks at the same time ...