[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1170
  • Last Modified:

WITH - ENDWITH visibility scope - call for VFP gurus

I am just discussing WITH - ENDWITH visibility scope together with several VFP programmers and the question is if the WITH - ENDWITH structure visibility in called function is a mistake or correct implementation. See the following code and tell what you think about it.

Note to non-FoxPro programmers: I hope the example is simple enough, so no need to explain its intention. The MoveForm function visibility is public and you may call it from "anywhere" by design.

TIA for all your responses!


RELEASE oForm
PUBLIC oForm
oForm = CREATEOBJECT("Form")

WITH oForm
  .Visible = .T.
  MoveForm(20,20)
ENDWITH

FUNCTION MoveForm
LPARAMETERS lnTop, lnLeft

.Top = lnTop
.Left = lnLeft

RETURN

Open in new window

0
pcelba
Asked:
pcelba
  • 4
  • 3
  • 2
  • +1
3 Solutions
 
tusharkanvindeCommented:
I would avoid such coding and pass the form as a parameter

You can also check http://fox.wikis.com/wc.dll?Wiki~WithLeaksLocals for WITH /  ENDWITH visibility of local variables.
0
 
CaptainCyrilCommented:
RELEASE oForm
PUBLIC oForm
oForm = CREATEOBJECT("MyForm")
oForm.Visible = .T.

WITH oForm
  .Visible = .T.
  .MoveForm(20,20)
ENDWITH

DEFINE CLASS MyForm AS Form

      PROCEDURE MoveForm
      LPARAMETERS lnTop, lnLeft
      .Top = lnTop
      .Left = lnLeft

ENDDEFINE
0
 
pcelbaAuthor Commented:
This is just OO format of the same code.

Why should we design functions or methods which require calls from inside the WITH-ENDWITH structure?

I agree to tusharkavninde and I am also avoiding such coding.

OTOH, it was probably designed this way otherwise compiler would refuse commands and references beginning with dot.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
CaptainCyrilCommented:
I did not know it was you, Pavel, till you answered.

I did not know that you could do that in Fox. Fox is amazing :-)
0
 
pcelbaAuthor Commented:
:-)

Yes, VFP has so many features but some of them are not finished yet... Did you ever use e.g. Class Member Arrays? (http://msdn.microsoft.com/en-us/library/9dxf4h4d(VS.80).aspx)

0
 
Olaf DoschkeSoftware DeveloperCommented:
I didn't know this but wouldn't make use of it, no matter if it's a feature or a bug. I actually wouldn't want to decide if it's a bug that would need a fix. Maybe it's somehow connected to the feature of being able to run code in suspend mode in the command window, as if it was actually in the current suspended method, which is awfully helpful in debugging code.

Of course you can actually do without WITH..ENDWITH and it's intellisense issues, even if those are halfways fixed. It's a good idea to not have a RETURN statement within WITH ENDWITH for the same reason you're staying in the context and missing a cleanup of the reference WITH starts and ENDWITH end. So it's only half a surprise this context is working the other way around in a function called from within a WITH ... ENDWITH.

Bye, Olaf.
0
 
Olaf DoschkeSoftware DeveloperCommented:
Actually, when RETURNing from within WITH .. ENDWITH you don't stay in the context and can't adress some property or method via .something, but there was another good reason to not RETURN, I think you introduce a dangling object reference, if the ENDWITH is not executed, something along those lines.

Bye, Olaf.
0
 
pcelbaAuthor Commented:
Dhaest, you are like my wife - everything mest be cleaned up at Christmas :-))

OTOH, we cannot expect additional contributions, so I'll close this question.

Marry Christmas and Happy New Year to all of you!
0
 
CaptainCyrilCommented:
You mean Merry ;-)
0
 
pcelbaAuthor Commented:
Oops.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 4
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now