Solved

Form Close

Posted on 2004-04-20
7
171 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
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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
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

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi Dbf export problem to a Visual Foxpro application 6 208
Delphi: Connect to running MS Outlook 4 123
Delphi: making a BW image transparent 10 62
MS Access from Delphi 31 61
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…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

830 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