?
Solved

WITH - ENDWITH visibility scope - call for VFP gurus

Posted on 2010-11-29
11
Medium Priority
?
1,131 Views
Last Modified: 2012-08-14
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
Comment
Question by:pcelba
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
  • +1
11 Comments
 
LVL 14

Accepted Solution

by:
tusharkanvinde earned 668 total points
ID: 34230789
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
 
LVL 27

Assisted Solution

by:CaptainCyril
CaptainCyril earned 664 total points
ID: 34230889
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
 
LVL 42

Author Comment

by:pcelba
ID: 34231068
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
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 
LVL 27

Expert Comment

by:CaptainCyril
ID: 34233029
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
 
LVL 42

Author Comment

by:pcelba
ID: 34233106
:-)

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
 
LVL 29

Assisted Solution

by:Olaf Doschke
Olaf Doschke earned 668 total points
ID: 34241847
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
 
LVL 29

Expert Comment

by:Olaf Doschke
ID: 34248266
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
 
LVL 42

Author Comment

by:pcelba
ID: 34421947
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
 
LVL 27

Expert Comment

by:CaptainCyril
ID: 34421954
You mean Merry ;-)
0
 
LVL 42

Author Comment

by:pcelba
ID: 34422001
Oops.
0

Featured Post

Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Progress

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question