Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Using BindEvent to close a form when parent closes
Message
De
12/07/2009 14:52:23
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Versions des environnements
Visual FoxPro:
VFP 9 SP1
Divers
Thread ID:
01411652
Message ID:
01411720
Vues:
44
Christof --

I could not get your suggested approach to work. It appears that all the Destroy events do not occur if there is a dangling reference. At least, that's what I read from the debugger.

However, your original (at the top of the message) works just fine. For my purposes, as it turns out, if FormB gets closed erroneously as part of a cancelled release process -- well, I can live with that.

Thanks

Jim

>Hi Jim,
>
>is that what you want. The following is the code for FormB::Init:
>
>Lparameters toForm
>Thisform.oForm = m.toForm
>BindEvent(toForm,"QueryUnload",This,"OnClosing")
>BindEvent(toForm,"Release",This,"OnClosing")
>
>And this is the OnClosing method in FormB:
>
>UnBindEvent(This.oForm,"QueryUnload",This,"OnClosing")
>UnBindEvent(This.oForm,"Release",This,"OnClosing")
>Thisform.Release
>
>What you can't really capture easily is whether the form actually closed. QueryUnload and Release both could cancel the release process. The FoxTabs project has some code that detects which forms have been closed. I think this uses BINDEVENTS() on the windows message level to capture messages like WM_CLOSE, etc. But it wasn't easy, if I recall correctly.
>
>In your case an easier approach might be something similar: Instead of storing references - which causes the dangling reference situation - you could add a proxy object to FormA from the Init of FormB. Pass the window handle of FormB, but do not store the reference to FormA. Now, in the proxy use the SendMessage() API function to send a WM_CLOSE message to FormB. Here's the FormB code for the Init event:
>
>Lparameters toForm
>toForm.NewObject(Sys(2015),"Proxy","Proxy.prg","",Thisform.HWnd)
>
>And here the code for the proxy class:
>
>Define Class Proxy as Custom
>  nHwnd = 0
>  Procedure Init(tnHwnd)
>    This.nHwnd = m.tnHwnd
>  Procedure Destroy
>    Declare Long SendMessage in Win32Api Long, Long, Long, Long
>    SendMessage(This.nHwnd,16,0,0)  
>EndDefine
>
Jim Nelson
Newbury Park, CA
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform