hakanfa
asked on
Form Close
Hello!
Is it possible to determine if a form is close from the Title Bar or if it is
programacally closed?
Hokki
Is it possible to determine if a form is close from the Title Bar or if it is
programacally closed?
Hokki
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(Send er: 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
var
bClose: Boolean = False;
procedure TForm1.Button1Click(Sender
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
begin
bClose: True;
end;
procedure TForm1.FormCloseQuery(Send
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
ASKER
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;
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;
How do You call it programatically close or from title bar ? :)
SendMessage(Form1.Handle,W M_SYSCOMMA ND,SC_CLOS E,0);
SendMessage(Form1.Handle,W
ASKER
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
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
This would work.
private
bCloseType: boolean;
procedure TForm1.FormCreate(Sender: TObject);
begin
bCloseType := False;
end;
procedure TForm1.FormActivate(Sender
begin
bCloseType := False;
end;
procedure TForm1.Button1Click(Sender
begin
bCloseType := True;
Close;
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
if bCloseType then
Application.MessageBox('Cl
end;