Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to get the object value from parent form ?
Message
De
23/05/2014 05:53:51
Dragan Nedeljkovich (En ligne)
Now officially retired
Zrenjanin, Serbia
 
 
À
23/05/2014 03:15:22
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Versions des environnements
Visual FoxPro:
VFP 9 SP2
OS:
Windows Server 2008
Network:
Windows 2008 Server
Database:
Visual FoxPro
Application:
Desktop
Divers
Thread ID:
01600260
Message ID:
01600550
Vues:
60
>>An object will not be released as long as at least one reference to it exists. Storing reference to the parameter object in a property of the child form guaranteed that it'll be available as long as form exists.
>
>On testing, that seems to be true. However, I for one have never relied on that feature, I haven't seen it documented anywhere. You can end up with code that does not act as "expected", but throws no errors:
>
>CLEAR
>
>loParameter = CREATEOBJECT( "Custom" )
>loParameter.AddProperty( "MyString", "Hello World" )
>
>loMyChild = CREATEOBJECT( "MyChild", loParameter )
>
>loParameter.MyString = "Hello World 2"
>loMyChild.MyPrint( )
>
>* Section below does not throw any error
>* even though loParameter is not actually released
>loParameter.MyString = "Hello World 3"
>RELEASE loParameter
>loParameter = .NULL.
>loMyChild.MyPrint( )
>
>RETURN
>
>DEFINE CLASS MyChild AS Custom
>	MyPORef = ""
>	
>	FUNCTION Init
>		LPARAMETERS toParameter
>		
>		This.MyPORef = toParameter
>		
>		=This.MyPrint( )
>	
>	ENDFUNC
>	
>	FUNCTION MyPrint
>		? This.MyPORef.MyString
>		
>	ENDFUNC
>
>ENDDEFINE
>
The interesting part is that this is as it should be, but it takes some thinking to understand why. The moment you released loParameter, the variable was gone. In the next line, you issue a loParameter=null, but that's a new private variable, completely unrelated to the previous one, and that line does practically nothing, as your loMyChild.MyPopRef is still a reference to the original one.

The part which introduces confusion is when you release a variable and then use it again - not something you would regularly do (we have the local scope for automatically releasing variables), and surely something that would (at least should) look suspicious to anyone reading the code.

back to same old

the first online autobiography, unfinished by design
What, me reckless? I'm full of recks!
Balkans, eh? Count them.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform