Solved

Form Close

Posted on 2004-04-20
7
172 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Print Graphic and Text to Epson TM-T88v 12 567
QRReport  TQrmemo vertical stretching 1 68
shape, triangle, dbctrlgrid 3 47
Formating a integer number to float 2 10
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

710 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