Solved

WITH - ENDWITH visibility scope - call for VFP gurus

Posted on 2010-11-29
11
1,039 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
  • 4
  • 3
  • 2
  • +1
11 Comments
 
LVL 14

Accepted Solution

by:
tusharkanvinde earned 167 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 166 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 41

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
 
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 41

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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 29

Assisted Solution

by:Olaf Doschke
Olaf Doschke earned 167 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 41

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 41

Author Comment

by:pcelba
ID: 34422001
Oops.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
word0 challenge 3 58
wordappend challenge 8 85
What is Python programming? 3 66
Programatically extract date from website 8 17
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
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…

757 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now