Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

WITH - ENDWITH visibility scope - call for VFP gurus

Posted on 2010-11-29
11
Medium Priority
?
1,154 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 43

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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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 43

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 30

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 30

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 43

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 43

Author Comment

by:pcelba
ID: 34422001
Oops.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

"Disruption" is the most feared word for C-level executives these days. They agonize over their industry being disturbed by another player - most likely by startups.
Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
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 …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

618 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