Binsky
asked on
Easy question : How to let messagDlg respond to cancelclicks on closing form?
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,mb Ok, 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
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,mb
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.
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.
ASKER
(I did it the wrong way around I guess, read comment above for actual comment.)
?? confused
well glad you got it work,
even i don't know yet, how
meikl ;-)
well glad you got it work,
even i don't know yet, how
meikl ;-)
btw.
mondays are really hard days for me too :-))
mondays are really hard days for me too :-))
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