Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Easy question : How to let messagDlg respond to cancelclicks on closing form?

Posted on 2003-03-24
6
Medium Priority
?
206 Views
Last Modified: 2010-04-04
Hi there!

This should be an easy one :
In my application I use the messagedlg(...) to ask for user confirmation when they try to close the form (are you sure? Yes/No)

Now when I close the form through the FileMenu (TMainMenu->Exit) the messagedlg responds to the cancelclick.

But when I press the close-cross (in top-right corner) the popu doesn't respond to cancelclicks, and just blatantly closes the entire application.

Is there a big difference, and/or am I forgetting something?

btw, here's the messageDlg part I used :

if MessageDlg('This will close the program',mtConfirmation,mbOk,      mbCancel], 0) = mrOk then
begin
  Application.Terminate;// The end of the progame.
  AdminMain.ClearObjectList;
end
else ;  // Empty statement to let program respond to cancelclick

I think it has to do with the empty statement, is there another way to do this?

Thanks in advance

Robin
0
Comment
Question by:Binsky
  • 3
  • 2
6 Comments
 
LVL 27

Accepted Solution

by:
kretzschmar earned 200 total points
ID: 8193598
you should place the dialog in the onclosequery-event
of your mainform and modify the canclose-paramater to your
needs -> in case of cancel -> canclose := false;

further advice:

in your exit-menu-click-event just place only the close-method

supply the onclosequery event like

canclose := MessageDlg('This will close the program',mtConfirmation,mbOk,      mbCancel], 0) = mrOk ;  

move this like
into the formdestroy-event of the main-form

AdminMain.ClearObjectList;

meikl ;-)
0
 
LVL 2

Expert Comment

by:Ratje
ID: 8193722
or try using this :

procedure WMSysCommand(var Msg: TWMSysCommand); message WM_SYSCOMMAND;

procedure TForm1.WMSysCommand;
begin
  if (Msg.CmdType=SC_ClOSE) then
    // show your dialog
  else
    DefaultHandler(Msg);
end;

or to disable the 'x'-button :

procedure TForm1.FormCreate(Sender: TObject);
var
  hMenuHandle: Integer;
begin
  hMenuHandle := GetSystemMenu(Handle, False);
  if (hMenuHandle <> 0) then
    DeleteMenu(hMenuHandle, SC_CLOSE, MF_BYCOMMAND);
end;

Rat
0
 
LVL 1

Author Comment

by:Binsky
ID: 8194780
Hi Kretzschmar! (and others of course...)

It took me a bit to find out exactly what you meant, (I wasn't reading it right, it was still a bit too much of the monday morning I guess) but that was exactly it!

I was trying to add your idea to the onclose event, which was essentially the same as what I had...But after my lunchbreak I actually saw what you wrote down...Tried it, and it worked (but you knew that!) The onclose will always close, except if the canclose bool is false. Good trick!

I also found out why my mainmenu=>exit_click did work, it didn't call the onclose, which windows "buttons" do!

Another day, another lesson!

Thankx, the 50 points are yours.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 1

Author Comment

by:Binsky
ID: 8194788
(I did it the wrong way around I guess, read comment above for actual comment.)
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 8194821
?? confused

well glad you got it work,
even i don't know yet, how

meikl ;-)
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 8194834
btw.
mondays are really hard days for me too :-))
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Loops Section Overview
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses
Course of the Month13 days, 17 hours left to enroll

581 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question