Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Message Box on close

Posted on 2003-11-16
13
Medium Priority
?
377 Views
Last Modified: 2010-05-19
I just can't figure out how to have a message box like "Do you really want to quit?" displayed when i close the program...
Can someone help me plz ?
Thanx in advance
0
Comment
Question by:Professor
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
  • 4
13 Comments
 
LVL 8

Expert Comment

by:gmayo
ID: 9758240
procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
      CanClose := (MessageDlg('Are you sure you want to quit?', mtConfirmation, [mbYes, mbNo], 0) = mrYes);
end;

Geoff M.
0
 

Expert Comment

by:Shinez
ID: 9758255
Try this

procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);

begin
  if MessageDlg('Close the form?', mtConfirmation, [mbOk, mbCancel], 0) = mrCancel then
     CanClose := False;
end;
0
 

Author Comment

by:Professor
ID: 9758468
That still doesn't ask me when i close the form though ...
I don't know if this is difficult or if im just too stupid *lol*

Its about like this vb6 code:

sub Form1.Unload(Cancel as Boolean)
 res=msgbox("Quit?","whatever",vbYesNo)
 if res=vbYes then
  Cancel=true
 end if
end sub
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.

 

Expert Comment

by:Shinez
ID: 9758472
vb6? you want delphi OnCloseQuery?

it works fine play with it experiment with diffrent ways of doing it in delphi, there is not just 1 way of doing things,
0
 

Expert Comment

by:Shinez
ID: 9758479
if your using delphi then on your form in "Object Inspector" make sure you have form1/anything in the dropdown box above and then click events, then look for OnCloseQuery and then double click on the space next to it and then put the code above into the OnCloseQuery in your code area.
0
 

Author Comment

by:Professor
ID: 9758696
Still not showing anything...
0
 

Author Comment

by:Professor
ID: 9758705
Or did something change from delphi 6 to delphi 7?
0
 
LVL 8

Accepted Solution

by:
gmayo earned 1000 total points
ID: 9758706
Your unit should look something like this:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, ImgList, Menus;

type
  TForm1 = class(TForm)
    procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
      CanClose := (MessageDlg('Are you sure you want to quit?', mtConfirmation, [mbYes, mbNo], 0) = mrYes);
end;

end.

The FormCloseQuery is called whenever the form is about to be closed. Setting the CanClose to false will prevent it closing. You need to ensure that the form's FormCloseQuery event handler (in the object inspector as Shiner said) is pointing to the procedure.

Geoff M.
0
 

Expert Comment

by:Shinez
ID: 9758709
are you sure your using delphi, before you showed vb6 source.
0
 

Expert Comment

by:Shinez
ID: 9758715
ya gmayo you sort him out, I got to make sunday roast.
0
 

Author Comment

by:Professor
ID: 9758721
Yes I was actually using delphi ... And it works now thanks very much :)
0
 
LVL 8

Expert Comment

by:gmayo
ID: 9758722
My example was on Delphi 7, however, it's been the same since at least Delphi 4.

Geoff M.
0
 
LVL 8

Expert Comment

by:gmayo
ID: 9758755
BTW you can delete the other question and get your points refunded by posting in http://www.experts-exchange.com/Community_Support/ with the question URL and a message saying "please delete/refund".

Geoff M.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses

660 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