> I am writing an Active Form in D6, and found that if it created an
> ActiveFormDestroy handler for the form's OnDestroy event, it never got
> called. The OnCreate event was fired without any problems.
> After some investigation, I found the following:
> 1. OnCreate is called before the event sink is set up. That is why it works
> fine.
> 2. When the event sink is set up, the events OnActivate, OnClick, OnCreate,
> OnDblClick, OnDeactivate, OnDestroy, OnKeyPress and OnPaint all get
> overwritten in TActiveFormX.Initialize. I don't understand event sinks (I
> just want to write a form to run in a browser), so I don't know if the
> original values were supposed to have been copied into FEvents.
> 3. In any case, when I close the browser, the TActiveFormX.DestroyEvent
> procedure gets called, only to find FEvents is nil.
> 4. The BeforeDestruction procedure finds that the OnDestroy event is nil.
> I found two possible ways to overcome this and ensure my OnDestroy handler
> gets called, and I wonder which is the more correct:
> 1. Comment out the OnCreate and OnDestroy assignments in
> TActiveFormX.Initialize. The OnCreate handler has already been called
> anyway, and by the time we want the OnDestroy event, we are on our way out
> anyway. Is there a reason to sink OnCreate and OnDestroy?
> 2. Override TActiveFormX.BeforeDestruction and re-assign OnDestroy :=
> ActiveFormDestroy; before calling inherited BeforeDestruction. This ensures
> that the inherited BeforeDestruction procedure finds and OnDestroy handler
> to execute.
> I noticed that the first method happens earlier in the cleanup process (it
> happens even before BeforeDestruction is called), but I've no idea how to
> decide which method to use.
> Any advice would be very much appreciated.
Just override "Destroy" and don't even bother with "OnDestroy".