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 03:41:07
 
 
À
11/07/2009 20:47:17
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:
01411670
Vues:
58
>I have the following case:
>
>FormA opens FormB, passing an object reference to FormB.
>
>Thus the Init in FormB looks like this
Lparam toObject
>This.oObject = toObject
>
>I would like to use BindEvent here so that closing FormA close will close FormB. (This is essential, since the object reference keeps FormA from closing..)
>
>Can anybody tell me that the call to BindEvent should look like?
>

I agree with Greg that the Linked clause of the Do Form command might help. On the other hand, if childForm also stores a parentForm reference, a childForm reference inside parentForm looks quite cyclic, and might eventually cause a dangling reference, wouldn't it?

In the following example, BINDEVENT(parentForm,'Destroy', childForm,'RemoteRelease') seems to work:
PUBLIC oForm as Form, oForm2 as Form
oForm = CREATEOBJECT('TestForm')
oForm.Show()
RETURN

DEFINE CLASS TestForm as Form
	AutoCenter = .T.

	ADD OBJECT cmdChildForm as Commandbutton WITH ;
		Left = 100, Top = 100, Height = 24, Caption = "Child Form"
	PROCEDURE cmdChildForm.Click
		IF VARTYPE(m.oForm2) <> 'O'
			oForm2 = CREATEOBJECT('ChildForm',Thisform)
			BINDEVENT(Thisform,'Destroy', m.oForm2,'RemoteRelease')
		ENDIF
		oForm2.Show()
	ENDPROC
	PROCEDURE Destroy
		UNBINDEVENTS(This)
	ENDPROC
ENDDEFINE

DEFINE CLASS ChildForm as Form
	oParentForm = .Null.
	PROCEDURE Init(toParentForm)
		This.oParentForm = m.toParentForm
	ENDPROC
	PROCEDURE RemoteRelease
		Thisform.Release()
	ENDPROC
	PROCEDURE Destroy
		This.oParentForm = .Null.
	ENDPROC
ENDDEFINE
hth
-Stefan
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform