Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Close and exit under a file menu.

123 views
Skip to first unread message

Patrick Sabourin

unread,
Jul 30, 1998, 3:00:00 AM7/30/98
to
I am writing (learning) a small Delphi 3 and 4 application.
I would like to have under the File menu (that I create) an Exit menu
item.

My application will open another form. I would like Delphi to display a
close menu item and a disabled exit button. I am not sure what the code
for the close menu item should be. I have looked at several places but
could not find a definite resource to help me out.

I would also like to force the users to exit the application only from
the main screen with the file|exit menu.

Is this possible?
What kind of code should be under the Exit's and Close's onclick event?
Thanks

--
-----------------------------------------------------------
Patrick Sabourin
email: patrick_...@technologist.com
web site: http://surf.to/patrick-sabourin

"Even a mosquito doesn't get a slap on the back until
he starts to work."
-Unknown
-----------------------------------------------------------

Ken White

unread,
Jul 30, 1998, 3:00:00 AM7/30/98
to
Patrick,

procedure TForm1.FileExit1Click(Sender: TObject);
begin
Application.Terminate;
end;

As far as disabling the close button, I presume you're talking about
the 'X' in the upper right corner of the form. The easiest way of
handling this is to remove the System Menu using the form's
BorderIcons property.

Ken
--
Ken White
kwh...@westelcom.com

Clipper Functions for Delphi
http://members.aol.com/clipfunc/

Patrick Sabourin

unread,
Jul 31, 1998, 3:00:00 AM7/31/98
to
I take it that the Application.Terminate command would be used in under
File|Exit.

What code would be under the File|Close of the second form so that the second
form closes, leaves the application still running and I can continue to work
in the main menu?

PS: I had also meant the 'X' button. I would also like to know the
File|Close button.

Thanks

jph

unread,
Jul 31, 1998, 3:00:00 AM7/31/98
to
Patrick,

Actually, a simple "Close" or "FormX.Close" would work in BOTH cases (and, IMO
is the more common practice). When you "Close" the main form of the
application, Application.Terminate is automatically called.

There are several ways of preventing the application (or any particular form)
from closing. Usually the best thing to do is use the "OnCloseQuery" event of
the form to check if you want to allow the close to occur. If not, simply set
the "CanClose" variable to false. For example, in your Form1.OnCloseQuery you
could do this:

CanClose := NOT Form2.visible;

By the way, yet another way of preventing the user from closing the
application while Form2 is open is to open Form2 "modally" using
Form2.ShowModal
This would prevent the user from accessing anything on Form1 until Form2 is
closed.

I am not quite sure what you meant by:


> > > My application will open another form. I would like Delphi to display a
> > > close menu item and a disabled exit button.

WHERE do you want these menu items to appear? if you never want to allow an
EXIT from Form2, then why have an EXIT menuitem on that form at all?

Hope this helps.

-jph

0 new messages