Solved

Minimize a form on close

Posted on 2004-04-08
4
317 Views
Last Modified: 2010-04-05
Looking for a function or procedure that will minimize my app when I click on the close button instead of closing it.
0
Comment
Question by:voodoo22
  • 2
  • 2
4 Comments
 
LVL 26

Accepted Solution

by:
Russell Libby earned 50 total points
ID: 10789301

Pick up the OnCloseQuery and handle the close there, eg:

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

  CanClose:=False;
  Application.Minimize;

end;


And of course, you will need to be able to actually "close/terminate" the application at some point, so using either the following

procedure TForm1.Button1Click(Sender: TObject);
begin

  PostQuitMessage(0);

end;

Or

Application.Terminate

can be used to close the app. Really comes down to catching the WM_CLOSE message and overriding the base functionality.

Regards,
Russell

0
 

Author Comment

by:voodoo22
ID: 10789381
Oops I accepted your answer aiil to early... I tried adding the above procedure to my form and then added this under it but it's not working...

procedure TForm1.Button1Click(Sender: TObject);
begin
  If Checkbox1.Checked then
    FormCLoseQuery(Application,False);
  else
    Application.Terminate;
end;
0
 

Author Comment

by:voodoo22
ID: 10789410
Ok now I see what you are doing but it will not work for me.

What I need is a function that I can use in for the buttons OnClick Event. As you can prob guess from my BAD code above what I am trying to do is give the user the option to minimize the form when the [X] button is pressed or to close it like normal and the way you have it I can't really do that from a button click.
0
 
LVL 26

Expert Comment

by:Russell Libby
ID: 10791233
What I posted will work for you, but not the way you have coded it. (You also should mention these things in the initial question).

procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
 
  // If checkbox is marked, just minimize the form
  if Checkbox1.Checked then
  begin
    CanClose:=False;
    Application.Minimize;
  end
  else
    CanClose:=True;

end;

procedure TForm1.Button1Click(Sender: TObject);
begin

  If Checkbox1.Checked then
    Close
  else
    PostQuitMessage(0)

end;

------------
Russell
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

867 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now