On Feb 28, 2007, at 07:02 UTC, Tim Hare wrote: > OK, let's try a stupid little example. Let's say I start a new > project and on Window1, I drag out 2 pushbuttons. Now I put the > following code into the action event of PushButton1: > > static myCount as integer > myCount= myCount+ 1 > me.Caption= str(myCount) > > When I push the button, it increments the number shown on the button. > I think that's pretty cool, so I do the same thing in PushButton2.
In other words, now you have two static variables. One in PushButton1.Action and another in PushButton2.Action. Two static variables, ergo two separate values. > It occurs to me at this point that instead of copying the code from > button to button, that a subclass would be easier and a lot more fun. > So I create a class, call it myButton and make its super PushButton. > I copy my code into the Action event and I'm ready to roll. But at this point, there is only one static variable, ergo one value. I know you understand this, and I guess I can see how a new user might make this mistake if they don't understand what "static" means. But I fear that your claim that static variables in a control action event in a window are somehow "subtly different" from static variables anywhere else doesn't contribute to understanding -- it just causes confusion. There is no difference, none whatsoever. It's exactly the same as this: 1. Two subclassses of Foo (say, SubFooA and SubFooB), with a static variable in both SubFooA.Bar and SubFooB.Bar. Versus... 2. Moving this code to the superclass, Foo.Bar. In case 1, there are two static variables and in case 2, there is only one. Exactly the same as your example. It's not that the static variable is any different; it's that having two static variables is different from having one. This is an "of course" sort of situation, once you see the very simple rule that each place "static" appears defines a new global (yet only locally available) variable. Best, - 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>
