Solved

Form Close

Posted on 2004-04-20
7
167 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
7 Comments
 
LVL 17

Expert Comment

by:mokule
Comment Utility
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
Comment Utility
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
Comment Utility
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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 17

Expert Comment

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

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

Author Comment

by:hakanfa
Comment Utility
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
Comment Utility
Closed, 125 points refunded.
modulo
Community Support Moderator
Experts Exchange
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

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…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

772 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

11 Experts available now in Live!

Get 1:1 Help Now