Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. google. articles. downloads. faq. members. weblogs. file info. rss.
 From: Olaf Doschke
  Where is Olaf Doschke?
 Hamburg
 Germany
 Olaf Doschke
 To: Mike Yearwood
  Where is Mike Yearwood?
 Toronto
 Canada
 Mike Yearwood
 Tags
Subject: RE: how to check memory variable is created
Thread ID: 188233 Message ID: 188952 # Views: 1 # Ratings: 1
Version: Visual FoxPro 7 Category: General VFP Topics
Date: Tuesday, August 12, 2008 7:15:25 PM         
   


Hi Mike,

> If asno was declared as PRIVATE or PUBLIC or worse yet, undeclared but populated

This makes me think you did not understand that a variable is never DECLARED private.
To make a variable with private scope (that is public to this stacklevel and further)
you need to RELEASE variable and tehn populate it.

PRIVATE variable

is no declaration, it's stopping the private scope of a previous
private variable and guarantue for your own code after this,
that variable does NOT exist in private scope, so you can
create it private again.

Variablescopedemo()

Procedure Variablescopedemo()
   RELEASE plError && reset to default state: no var plError exists
   plError = .T.   && populate undeclared variable => make it private
   ? Vartype(plError)
   ? "list memory:"
   LIST MEMORY LIKE plError && plError is listed as a private "Priv" variable

   RELEASE plError && reset to default state: no var plError exists
   PRIVATE plError && "declare" plError (not)
   ? Type("plError") && "U"
   ? "list memory:"
   LIST MEMORY LIKE plError && plError is not listed, it's not there
Endproc


Now execute these commands one by one in the command window:

RELEASE plError
plError = .T.
LIST MEMORY LIKE plError && plError is listed as a public "Pub" variable


Surprise. Although that's not the point, you see public
variables are just a special kind of private ones, the're
populated at the highest (or lowest, as you prefer) call
stack level.



See the syntax of PRIVATE is very alike to that of a
certain type of RELEASE, eg

RELEASE ALL LIKE *
PRIVATE ALL LIKE p*


It's there so you can assure if you populate a variable
in that name space you will declare a new one and not
work on an outside defined private (or public) variable.

Execute this as a prog or selection (NOT one by one)

PUBLIC goApp
goApp = "Foxpro"
Variablescopedemo2()
? goApp

Procedure Variablescopedemo2()
   PRIVATE goApp
   ? Type("goApp")
Endproc


See you can also switch off global variables with PRIVATE,
but it's not like release, compared to forms it's like the
difference of release vs. hide.

So private helps you to mask out variables you plan to
use with a private scope yourself.

In comparison to a datasession without a
PRIVATE ALL LIKE * you're working in the global
variable session, with PRIVATE ALL LIKE * you're
starting a new private variable session.

It's dangerous to make use of PRIVATE as long as you
don't know how it works. In general you can skip it's
use if you always declare your variables LOCAL despite
of that one PUBLIC goApp variable. But you may not
be failsafely and a typo in a name may make it private
instead of the LOCAL var you declared.

PRIVATE ALL LIKE l* would help you prevent the
injection of the current procedure/function/method
with some variable that was meant to be local
but due to a type is private. On the other hand
PRIVATE ALL LIKE p* will not help with this at all,
it will just turn down variables meant PRIVATE to
work as intended.

If you suspect all other programmers don't bother at
all about naming conventions and variable declartions,
give PRIVATE ALL EXCEPT goApp a chance...


And finally, to reconnect to the initial problem,
a PRIVATE "declaration" can be the reason a variable
or parameter does NOT exist or is not VISIBLE after
that PRIVATE command.



By the way even though it's been some time for you now
as an MVP and I am rather late with this, my congrats!!
I'm looking forward to meet you some day, perhaps next
summit, if I stay MVP in 2009. Southwest is also

Bye, Olaf.

ENTIRE THREAD

how to check memory variable is created Posted by HYDER ZAMAN @ 8/8/2008 8:57:55 AM
RE: how to check memory variable is created Posted by Borislav Borissov @ 8/8/2008 9:03:09 AM
RE: how to check memory variable is created Posted by vinod kabdal @ 8/8/2008 9:57:37 AM
RE: how to check memory variable is created Posted by surinder singh @ 8/8/2008 10:15:44 AM
RE: how to check memory variable is created Posted by HYDER ZAMAN @ 8/8/2008 11:57:05 AM
RE: how to check memory variable is created Posted by Glenn Villar @ 8/8/2008 10:30:24 AM
RE: how to check memory variable is created Posted by surinder singh @ 8/8/2008 10:35:17 AM
RE: how to check memory variable is created Posted by Glenn Villar @ 8/8/2008 10:40:09 AM
RE: how to check memory variable is created Posted by HYDER ZAMAN @ 8/8/2008 12:00:34 PM
RE: how to check memory variable is created Posted by Mike Yearwood @ 8/10/2008 8:41:00 PM
RE: how to check memory variable is created Posted by Olaf Doschke @ 8/8/2008 12:15:31 PM
RE: how to check memory variable is created Posted by Allan Cerrudo @ 8/8/2008 12:42:00 PM
RE: how to check memory variable is created Posted by Tamar Granor @ 8/8/2008 10:46:34 PM
RE: how to check memory variable is created Posted by Mike Yearwood @ 8/10/2008 2:56:39 PM
RE: how to check memory variable is created Posted by suhas hegde @ 8/10/2008 9:04:44 PM
RE: how to check memory variable is created Posted by Borislav Borissov @ 8/10/2008 9:17:57 PM
RE: how to check memory variable is created Posted by Tamar Granor @ 8/11/2008 10:32:43 PM
RE: how to check memory variable is created Posted by Mike Yearwood @ 8/11/2008 4:23:39 PM
RE: how to check memory variable is created Posted by Borislav Borissov @ 8/11/2008 5:31:21 PM
RE: how to check memory variable is created Posted by Mike Yearwood @ 8/11/2008 6:51:51 PM
RE: how to check memory variable is created Posted by Borislav Borissov @ 8/11/2008 7:15:55 PM
RE: how to check memory variable is created Posted by Mike Yearwood @ 8/11/2008 8:00:10 PM
RE: how to check memory variable is created Posted by Olaf Doschke @ 8/12/2008 7:15:25 PM
RE: how to check memory variable is created Posted by Samir Ibrahim @ 8/16/2008 5:28:53 PM
RE: how to check memory variable is created Posted by Olaf Doschke @ 8/18/2008 9:26:59 PM
RE: how to check memory variable is created Posted by Carlos Alloatti @ 8/10/2008 4:16:02 PM
RE: how to check memory variable is created Posted by venkata krishnan @ 8/18/2008 9:26:05 AM