Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show dialog box with two buttons ( Continue / Close ) in Delphi

I want to create a warning dialog box which asks the users if the information typed during signup was correct, and asks him wether he want to continue or close that dialog and correct his information.

like image 487
Rafik Bari Avatar asked Dec 22 '11 12:12

Rafik Bari


4 Answers

var
  td: TTaskDialog;
  tb: TTaskDialogBaseButtonItem;
begin
  td := TTaskDialog.Create(nil);
  try
    td.Caption := 'Warning';
    td.Text := 'Continue or Close?';
    td.MainIcon := tdiWarning;
    td.CommonButtons := [];

    tb := td.Buttons.Add;
    tb.Caption := 'Continue';
    tb.ModalResult := 100;

    tb := td.Buttons.Add;
    tb.Caption := 'Close';
    tb.ModalResult := 101;

    td.Execute;

    if td.ModalResult = 100 then
      ShowMessage('Continue')
    else if td.ModalResult = 101 then
      ShowMessage('Close');

  finally
    td.Free;
  end;
end;

enter image description here

Note: This will only work on Windows Vista or later.

like image 50
Mikael Eriksson Avatar answered Oct 26 '22 18:10

Mikael Eriksson


if delphi then

if mrYes=MessageDlg('Continue?',mtwarning,[mbYes, mbNo],0) then 
  begin
        //do somthing
  end
else
exit; //go out
like image 42
PresleyDias Avatar answered Oct 26 '22 17:10

PresleyDias


var
  AMsgDialog: TForm;
  abutton: TButton;
  bbutton: TButton;
begin

  AMsgDialog := CreateMessageDialog('This is a test message.', mtWarning,[]);
  abutton := TButton.Create(AMsgDialog);
  bbutton :=  TButton.Create(AMsgDialog);

  with AMsgDialog do

    try

      Caption := 'Dialog Title' ;
      Height := 140;
      AMsgDialog.Width := 260 ;

      with abutton do
      begin
        Parent := AMsgDialog;
        Caption := 'Continue';
        Top := 67;
        Left := 60;
        // OnClick :tnotyfievent ;
      end;

      with bbutton do
      begin
        Parent := AMsgDialog;
        Caption := 'Close';
        Top := 67;
        Left := 140;
        //OnClick :tnotyfievent ;
      end;

       ShowModal ;

    finally
      abutton.Free;
      bbutton.Free;
      Free;
    end;

enter image description here

like image 37
VibeeshanRC Avatar answered Oct 26 '22 18:10

VibeeshanRC


Based on this:

procedure HookResourceString(rs: PResStringRec; newStr: PChar);
var
  oldprotect: DWORD;
begin
  VirtualProtect(rs, SizeOf(rs^), PAGE_EXECUTE_READWRITE, @oldProtect);
  rs^.Identifier := Integer(newStr);
  VirtualProtect(rs, SizeOf(rs^), oldProtect, @oldProtect);
end;

const
  SContinue = 'Continue';
  SClose = 'Close';

procedure TForm1.Button1Click(Sender: TObject);
begin
  HookResourceString(@SMsgDlgOK, SContinue);
  HookResourceString(@SMsgDlgCancel, SClose);
  if MessageDlg('My Message', mtConfirmation, [mbOK, mbCancel], 0) = mrOK then
  begin
    // OK...
  end;
end;
like image 28
kobik Avatar answered Oct 26 '22 16:10

kobik