On Feb 27, 2007, at 22:46 UTC, Tim Hare wrote:

> A word of caution regarding static variables.  When used in a method
> in a class definition, static variables are global to all instances
> of that class.

In other words, there is only one instance of that variable, which
retains its value from call to call (regardless of what object you call
it by), and which is accessible only within that method.

> When used in a method of, say, a window, then they
> are local to the window and act like statics from other languages,
> retaining their value from one call to the next.

In other words, there is only one instance of that variable, which
retains its value from call to call (regardless of what object you call
it by), and which is accessible only within that method.

It is exactly the same in both cases.  I don't understand the
distinction you're trying to make, and AFAIK, there is none to be made.
 
> Let's say we subclass a push button, and we want to retain a counter
> of the number of times it's been pushed...
> 
> One might expect myLocalCount to be nicely hidden in the action
> event, just like a local variable, but retaining its value from one
> push to the next. What will happen, however, is that all instances of
> our pushbutton class will share the same variable.

Of course.  That's the whole point of a static variable: it exists only
once, like a global, except that it's accessible only within the method
where it's declared.

This has nothing to do with windows or controls; it'd be exactly the
same in any other class (or module, for that matter) method.  Right?

Cheers,
- Joe

--
Joe Strout -- [EMAIL PROTECTED]
Verified Express, LLC     "Making the Internet a Better Place"
http://www.verex.com/

_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>

Reply via email to