Board index » cppbuilder » Re: TApplication

Re: TApplication


2007-01-15 02:36:54 AM
cppbuilder33
bar wrote:
Quote
Hello all
I have created an application using BCB 6.0. it has only one form.
I need to execute some statements before the application is closed.
The The TForm::OnClose() event of the form is invoking only when the
form closes. But when we close the close the running application
from the 'Windows Task Manager Window' and from the 'Taskbar
Rightclick pop-up Menu', how can we recognize the close of the
application

Thanks
SA
If you kill it using the Task Manager, there is nothing you can do.
That is why Task Manager usually gives you a warning that all data may
be lost.
If you kill it using the right click menu in the taskbar, the main
window will have to be closed too, so you can use TForm::OnClose(). Try
it.
--
Rudy Velthuis [TeamB] rvelthuis.de/
"Barabási's Law of Programming: Program development ends when the
program does what you expect it to do ?whether it is correct or
not." -- Albert-Lászl?Barabási
 
 

Re:Re: TApplication

Rudy Velthuis [TeamB] wrote:
Quote
bar wrote:

>Hello all
>I have created an application using BCB 6.0. it has only one form.
>I need to execute some statements before the application is closed.
>The The TForm::OnClose() event of the form is invoking only when the
>form closes. But when we close the close the running application
>from the 'Windows Task Manager Window' and from the 'Taskbar
>Rightclick pop-up Menu', how can we recognize the close of the
>application
>
>Thanks
>SA

If you kill it using the Task Manager, there is nothing you can do.
That is why Task Manager usually gives you a warning that all data may
be lost.

If you kill it using the right click menu in the taskbar, the main
window will have to be closed too, so you can use TForm::OnClose().
Try it.
Create a new VCL application, select the form and give it the following
OnClose event handler:
void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action)
{
::ShowMessage("OnClose called");
}
Now start it, right-select the icon on the taskbar to get the context
menu, and select Close. You'll see the message appear.
Actually, even if you kill the application in the task manager, the
message still appears. I just tested that.
--
Rudy Velthuis [TeamB] rvelthuis.de/
"I begin by taking. I shall find scholars later to demonstrate
my perfect right."
-- Frederick (II) the Great
 

Re:Re: TApplication

"Rudy Velthuis [TeamB]" < XXXX@XXXXX.COM >wrote in message
Quote
Rudy Velthuis [TeamB] wrote:

>bar wrote:
>
>>Hello all
>>I have created an application using BCB 6.0. it has only one form.
>>I need to execute some statements before the application is closed.
>>The The TForm::OnClose() event of the form is invoking only when the
>>form closes. But when we close the close the running application
>>from the 'Windows Task Manager Window' and from the 'Taskbar
>>Rightclick pop-up Menu', how can we recognize the close of the
>>application
>>
>>Thanks
>>SA
>
>If you kill it using the Task Manager, there is nothing you can do.
>That is why Task Manager usually gives you a warning that all data may
>be lost.
>
>If you kill it using the right click menu in the taskbar, the main
>window will have to be closed too, so you can use TForm::OnClose().
>Try it.

Create a new VCL application, select the form and give it the following
OnClose event handler:

void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action)
{
::ShowMessage("OnClose called");
}

Now start it, right-select the icon on the taskbar to get the context
menu, and select Close. You'll see the message appear.

Actually, even if you kill the application in the task manager, the
message still appears. I just tested that.
Have you tried the OnRequestClose (or is it OnCloseRequest?)
I've had a problem with CloseEvents not firing in the main form
under certain conditions (log on to windows as different user etc.)
and this seems to work. I can check the exact syntax in the morning.
 

{smallsort}

Re:Re: TApplication

Duane Hebert wrote:
Quote

"Rudy Velthuis [TeamB]" < XXXX@XXXXX.COM >wrote in message
news: XXXX@XXXXX.COM ...
>Rudy Velthuis [TeamB] wrote:
>
>>bar wrote:
>>
>>>Hello all
>>>I have created an application using BCB 6.0. it has only one form.
>>>I need to execute some statements before the application is
closed.>>>The The TForm::OnClose() event of the form is invoking
only when the>>>form closes. But when we close the close the
running application>>>from the 'Windows Task Manager Window' and
from the 'Taskbar>>>Rightclick pop-up Menu', how can we recognize
the close of the>>>application
>>>
>>>Thanks
>>>SA
>>
>>If you kill it using the Task Manager, there is nothing you can
>>do. That is why Task Manager usually gives you a warning that
>>all data may be lost.
>>
>>If you kill it using the right click menu in the taskbar, the main
>>window will have to be closed too, so you can use
>>TForm::OnClose(). Try it.
>
>Create a new VCL application, select the form and give it the
>following OnClose event handler:
>
>void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction
>&Action) {
>::ShowMessage("OnClose called");
>}
>
>Now start it, right-select the icon on the taskbar to get the
>context menu, and select Close. You'll see the message appear.
>
>Actually, even if you kill the application in the task manager, the
>message still appears. I just tested that.

Have you tried the OnRequestClose (or is it OnCloseRequest?)
Heheh. Hard to memorize. I had to look too: it is OnCloseQuery. <g>
That does, however, serve a slightly different purpose. It allows you
to stop the closing. But I assume it can be used for a similar purpose.
--
Rudy Velthuis [TeamB] rvelthuis.de/
"I want to die in my sleep like my grandfather...
not screaming and yelling like the passengers in his car..."
-- bumper sticker
 

Re:Re: TApplication

Rudy Velthuis [TeamB] wrote:
Quote
Actually, even if you kill the application in the task manager, the
message still appears. I just tested that.
You tested from the Application list. Indeed there it brings OnClose
as OnCloseQuery. But from the processlist it just kills whithout any events.
Also a destructor is useless whenn killed from the processlist.
Hans.
 

Re:Re: TApplication

"Rudy Velthuis [TeamB]" < XXXX@XXXXX.COM >wrote in message
Quote
Heheh. Hard to memorize. I had to look too: it is OnCloseQuery. <g>

That does, however, serve a slightly different purpose. It allows you
to stop the closing. But I assume it can be used for a similar purpose.
Yep. That's the one. It's probably intended to stop the
closing but you can put code in it and then accept the close.
I would prefer using the main form's dtor but it doesn't
get called in these scenarios either.
 

Re:Re: TApplication

"Hans Galema" < XXXX@XXXXX.COM >wrote in message
Quote
Rudy Velthuis [TeamB] wrote:

>Actually, even if you kill the application in the task manager, the
>message still appears. I just tested that.

You tested from the Application list. Indeed there it brings OnClose
as OnCloseQuery. But from the processlist it just kills whithout any
events.

Also a destructor is useless whenn killed from the processlist.
Unless you want to reset a watchdog when your app
stops. Putting critical code in the dtor makes sense
in most cases. With BCB we needed to use the
OnCloseQuery() to do this as the dtor wasn't
being called.
 

Re:Re: TApplication

Hans Galema wrote:
Quote
Rudy Velthuis [TeamB] wrote:

>Actually, even if you kill the application in the task manager, the
>message still appears. I just tested that.

You tested from the Application list. Indeed there it brings OnClose
as OnCloseQuery. But from the processlist it just kills whithout any
events.
Correct. When killed from the process list, there is simply nothing you
can do. Zilch, nada, rien, niks, nix.
--
Rudy Velthuis [TeamB] rvelthuis.de/
Customer: "I'm running Windows '95."
Tech: "Yes."
Customer: "My computer isn't working now."
Tech: "Yes, you said that."
 

Re:Re: TApplication

"Rudy Velthuis [TeamB]" < XXXX@XXXXX.COM >wrote in message
Quote
Correct. When killed from the process list, there is simply nothing you
can do. Zilch, nada, rien, niks, nix.
Is that correct? I thought that I tested it and the OnCloseQuery was
triggerred. I could be wrong as my main concern was that the dtor
wasn't fired when a user logged on as a different windows users.
OnCloseQuery definitely "solved" that. I don't have time to test
the task manager thing though.
 

Re:Re: TApplication

Duane Hebert wrote:
Quote

"Rudy Velthuis [TeamB]" < XXXX@XXXXX.COM >wrote in message
news: XXXX@XXXXX.COM ...

>Correct. When killed from the process list, there is simply nothing
>you can do. Zilch, nada, rien, niks, nix.

Is that correct? I thought that I tested it and the OnCloseQuery was
triggerred.
Didn't test that one yet. Will try...
Nope, neither OnCloseQuery nor OnClose were called, when I killed it
form the process list. But when killed from the application list, first
OnCloseQuery and then OnClose were called.
--
Rudy Velthuis [TeamB] rvelthuis.de/
"About the use of language: it is impossible to sharpen a pencil
with a blunt axe. It is equally vain to try to do it with ten
blunt axes instead." -- Edsger W. Dijkstra
 

Re:Re: TApplication

"Rudy Velthuis [TeamB]" < XXXX@XXXXX.COM >wrote in message
Quote
Nope, neither OnCloseQuery nor OnClose were called, when I killed it
form the process list. But when killed from the application list, first
OnCloseQuery and then OnClose were called.
Sounds right. ISTR testing killing it via the application list. What
I don't remember is whether the dtor was called in that case. As
I said, I know it wasn't when the user logged off windows but then
OnClose wasn't fired either.