Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Weird thing about .Destroy
Message
General information
Forum:
Visual FoxPro
Category:
Forms & Form designer
Miscellaneous
Thread ID:
00058959
Message ID:
00059059
Views:
31
>>>>>I have a nav button class which had some references to THISFORM.DataEnvironment. Of course, it was hosed when I dropped it into a form that was in a formset. So, I gave the navclass a property "oFormOrSet", and in a navclass method called from the .Init, I put this:
>>>>>
>>>>>
>>>>>* Figure out if it's a form or a formset,
>>>>>* set everything accordingly
>>>>>
>>>>>IF TYPE("THISFORMSET") = "O"
>>>>> THIS.oFormOrSet = THISFORMSET
>>>>>ELSE
>>>>> THIS.oFormOrSet = THISFORM
>>>>>ENDIF
>>>>>
>>>>>I used it to say things like .oFormOrSet.DataEnvironment. But when I needed it in the navclass.Destroy to clean up things in the DE, my reference was gone, even though THISFORMSET or THISFORM still existed. So I had to do something similar in the navclass.Destroy with a local variable:
>>>>>
>>>>>* the object reference THIS.oFormOrSet
>>>>>* seems to have been detroyed, even though
>>>>>* the form or formset still exists
>>>>>IF TYPE("THISFORMSET") = "O"
>>>>> oFormThis = THISFORMSET
>>>>>ELSE
>>>>> oFormThis = THISFORM
>>>>>ENDIF
>>>>>
>>>>>
>>>>>and then used it to say oFormThis.DataEnvironment. Is it really supposed to be this way?
>>>>
>>>>Personally, I would prefer to use Parent property to reach DE at the code point when it's really necessary (using TYPE(), of course). I try to abstain from using object reference variables/properties, just because it smells like invitation to troubles...
>>>
>>>How would you "use Parent property to reach DE"? I mention the DE in several places.
>>
>>You age going from some object on form, right? So, you first check Thisform.DE.Name or This.Parent.DE.Name. If its type is not "O", then you have thisformset and use This.Parent.Parent.DE or Thisform.Parent.DE
>
>And then you put the name in a form property? Like this:
>THIS.cFormName = THISFORMSET.Name or THISFORM.Name, whichever is appropriate? Then I suppose you use name substitution or macro substitution wherever you mention the DE, like (THIS.cFormName).DataEnvironment or whatever syntax works? I certainly don't want to check for the existence of a formset every time I mention the DE.


Just for the sake of throwing this in, I do use object reference variables. But Edward is right, they can lead to trouble so one must be quite cautious in using them. I've found the most convenient solution to their most frequent problem is to simply set them all to .NULL. in the destroy event of whatever has them as a property. It seems to work.

Steve Despres
Previous
Reply
Map
View

Click here to load this message in the networking platform