Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Am I the only one who did not know this?
Message
From
30/03/2011 19:50:29
 
General information
Forum:
Visual FoxPro
Category:
Object Oriented Programming
Miscellaneous
Thread ID:
00436744
Message ID:
01505616
Views:
122
>The click method of an okay button on a modal form I had the following code.
>
>Procedure cmdOkay.Click
>Local lcFile,lcType...
>
>With This.Parent && The parent is the modal form
> lcFile=.txtMergeFile.Value
> lcType=.comMergeType.Value
>EndWith
>*
>*Code to do the merging
>*
>
>...
>
>ThisForm.Release
>EndProc
>
>The form never released when the merging finished and the Release method was called. Obviously there was a dangling object reference somewhere. The only problem was I never refered to any objects in my code.
>
>However, when I changed "With This.Parent" to "With Thisform" everything worked fine. I am assuming that the "EndWith" does not clear any objects referenced
>by the "With" command. Am I correct in my understanding? Did anyone else know this already?
>
>Thanks
>Simon

I certainly did not know this, but I know there are other situations where WITH can cause trouble, for instance when you have a RETURN inside of a WITH.

I don't use WITH anymore in my code, because it does not really add to a better understanding of the code. Imagine seeing code like this:
WITH THISFORM
    .txtName.Value = "xxx"
    * etc

   WITH .listbox

       * lots of lines...
        .Width = 100

    ENDWITH
    
ENDWITH
If you look through the code and you see the dots, you always have to check in your brain what WITH you are currently referring to. I don't see WITH in other languages, except VBA. I used to use WITH all the time, but now I just find it annoying.
Christian Isberner
Software Consultant
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform