Solved

WITH - ENDWITH visibility scope - call for VFP gurus

Posted on 2010-11-29
11
1,083 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 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
How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
This is about my first experience with programming Arduino.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

860 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