Board index » delphi » Event OnBeforeClose is not fired from event OnDestroy

Event OnBeforeClose is not fired from event OnDestroy

Hi!

In the OnDestroy event of a form I have the code : ClientDataset1.Close
When it is executed the OnBeforeClose event of ClientDataset1 is not fired.
Then I remove the code and put it into OnClose event of the form. Now the
OnBeforeClose event is fired.

Why this happens ?

My problem is : this code have to be in OnDestroy event and I need the
OnBeforeClose event to be fired.

What can I do to solve this ?

Jose Carlos
Brazil

 

Re:Event OnBeforeClose is not fired from event OnDestroy


the destroy event is the last event of a component.
 it can not call the onclose..
  you should be calling Close which in turn should call the destroy..
etc...
 or you can instruct it to do so.
 but calling the destroy is the last door way.
P.S.
  you really should be using FREE if your handling the component from the
out side.
Quote
Jose Carlos wrote:
> Hi!

> In the OnDestroy event of a form I have the code : ClientDataset1.Close
> When it is executed the OnBeforeClose event of ClientDataset1 is not fired.
> Then I remove the code and put it into OnClose event of the form. Now the
> OnBeforeClose event is fired.

> Why this happens ?

> My problem is : this code have to be in OnDestroy event and I need the
> OnBeforeClose event to be fired.

> What can I do to solve this ?

> Jose Carlos
> Brazil

Re:Event OnBeforeClose is not fired from event OnDestroy


Jose,

Quote
> In the OnDestroy event of a form I have the code :

ClientDataset1.Close

Quote
> When it is executed the OnBeforeClose event of ClientDataset1 is not
fired.
> Then I remove the code and put it into OnClose event of the form. Now
the
> OnBeforeClose event is fired.

> Why this happens ?

Because it's too late. By the time the Form's OnDestroy is called, it's
already cleaned up all of its' components. Therefore, the ClientDataSet
is already gone.

Quote
> My problem is : this code have to be in OnDestroy event and I need the
> OnBeforeClose event to be fired.

Why does it *have* to be in OnDestroy?

Ken
---
Ken White
kwh...@adpsi.com

Clipper Functions for Delphi and C++ Builder
http://www.adpsi.com

Other Threads