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

x
?
Solved

Form Close

Posted on 2004-04-20
7
Medium Priority
?
175 Views
Last Modified: 2010-04-05
Hello!

Is it possible to determine if a form is close from the Title Bar or if it is
programacally closed?

Hokki
0
Comment
Question by:hakanfa
[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
7 Comments
 
LVL 17

Expert Comment

by:mokule
ID: 10875923
If You mean programatically - by Your aplication.
This would work.

  private
    bCloseType: boolean;


procedure TForm1.FormCreate(Sender: TObject);
begin
  bCloseType := False;
end;

procedure TForm1.FormActivate(Sender: TObject);
begin
  bCloseType := False;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  bCloseType := True;
  Close;
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  if bCloseType then
    Application.MessageBox('Closed programatically','Info',MB_OK);
end;
0
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10877801
hakanfa,

var
  bClose: Boolean = False;


procedure TForm1.Button1Click(Sender: TObject);
begin
 bClose: True;
end;


procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
 if bClose then
  ShowMessage('Closed by button!')
 else
  ShowMessage('Closed by Form!');
end;



If you are trying to prevent a user from closing the form from the Title Bar buttons, then you could do this:


var
  Form1: TForm1;

procedure TForm1.Button1Click(Sender: TObject);
begin
 bClose: True;
end;

procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
 if bClose then
 begin
  ShowMessage('Closed by button!');
  CanClose:= True;
 end
 else
 begin
  ShowMessage('Closed by Form!')
  CanClose:= False;
 end;
end;


Of course, the other way would be to set the form's BorderIcon's property (biSystemMenu) to false, and set the BorderStyle property to bsSingle.

Hope this helps!

Shane
0
 

Author Comment

by:hakanfa
ID: 10880484
Well actually i figured out by my self...

  private
    { Private declarations }
    procedure WMSysCommand(var Msg: TWMSysCommand); message WM_SYSCOMMAND;
.....

procedure TFrmLogin.WMSysCommand;
begin
  if Msg.CmdType = SC_CLOSE then
  begin
{Your code here}  
  end
  else
  begin
    inherited;
  end;
end;
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 17

Expert Comment

by:mokule
ID: 10880697
How do You call it programatically close or from title bar ? :)

  SendMessage(Form1.Handle,WM_SYSCOMMAND,SC_CLOSE,0);
0
 

Author Comment

by:hakanfa
ID: 10880775
Hello!
What I was looking for was to find out if a form is closed from the "Titlebar", and
the above code figures it out. If the user presses the(x) on the title bar the code
in {your code section} fires. Maybe I was not specific enough in my question.
Sorry for that!

Thanks anyway for You support pals,

Hokki
0
 

Accepted Solution

by:
modulo earned 0 total points
ID: 10911578
Closed, 125 points refunded.
modulo
Community Support Moderator
Experts Exchange
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

721 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