Thread: MessageDlg Help

    #1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2004
    Posts
    113
    Rep Power
    10

    MessageDlg Help


    I am asking too much questions today

    Code:
    procedure TfrmAbout.FormClose(Sender: TObject; var Action: TCloseAction);
    Var
    sel: Integer;
    begin
    MessageDlg('You are about to exit. Are you sure?',mtConfirmation, mbOKCancel, 0);
     if sel = mrOK     then Close();
    
      end;
    what if the user presses cancel? how can I return back to frmabout without any changes?
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jan 2004
    Location
    England
    Posts
    952
    Rep Power
    14
    Test the value returned by MessageDlg and if it is mrOK, the OK button was clicked.
    Code:
      if MessageDlg('You are about to exit. Are you sure?',
          mtConfirmation, mbOKCancel, 0) = mrOK then
        Action := caFree
      else
        Action := caNone;
  4. #3
  5. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,607
    Rep Power
    4247
    Your other option is to add code to the OnCloseQuery event instead of the OnClose event.
    Code:
    procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
    begin
        if MessageDlg('You are about to exit. Are you sure?',
          mtConfirmation, mbOKCancel, 0) = mrCancel then
            CanClose := false;
    end;
    Up the Irons
    What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
    "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
    Down with Sharon Osbourne

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2004
    Posts
    113
    Rep Power
    10
    thank u both for your help,

    now, is there a way to set 'cancel' button as a default option?
  8. #5
  9. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,607
    Rep Power
    4247
    Not that I know of, but you can make your own dialog form and make Cancel the default button for that form.
    Up the Irons
    What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
    "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
    Down with Sharon Osbourne

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo

IMN logo majestic logo threadwatch logo seochat tools logo