Special

Introducing the “Welcome to Xojo” Bundle!

New to Xojo and looking for guidance? We've put together a terrific bundle to welcome you! Xojo Bundle

This bundle includes six back issues of the magazine -- all of year 21 in printed book and digital formats -- plus a one-year subscription (beginning with 22.1) so you'll be learning all about Xojo for the next year. It's the perfect way to get started programming with Xojo. And you save as much as $35 over the non-bundle price!

This offer is only available for a limited time as supplies are limited, so hurry today and order this special bundle before the offer goes away!

Article Preview


Buy Now

Issue 4.1

COLUMN

Implementing the Monostate Pattern

Static Variables In Action

Issue: 4.1 (September/October 2005)
Author: Charles Yeomans
Author Bio: Charles is the author of "I Declare: Calling External Functions in REALbasic", available online at http://www.quantum-meruit.com/rb/
Article Description: No description available.
Article Length (in bytes): 5,947
Starting Page Number: 33
Article Number: 4115
Related Web Link(s):

http://www.quantum-meruit.com/rb/

Excerpt of article text...

REALbasic 2005 adds the concept of a static variable to the language. To get a grasp of this new addition, consider the concept of a local variable. A local variable is a chunk of storage allocated in a method. This variable is created anew every time the method executes, thus each executing copy of the method has its own local storage.

A static variable is also a chunk of storage allocated in a method. Unlike a local variable, a static variable is created and initialized once, remains in existence until the application quits, and is shared by all executing copies of the method. Like a local variable, the visibility of a static variable is limited to the method in which it is declared.

It is important to understand that static variables belong to the method, not the object or module to which the method is attached. Thus the creation and destruction of objects do not affect the value of static variables.

Static Properties

Static variables should not be confused with class properties, though they will be. Although REALbasic does not offer class properties, it is possible to implement the functionality of class properties using static variables, if not the syntax.

The initial temptation is to write a get/set pair of methods to express a class property, just as one can do for object properties. However, since static variables cannot be visible to two methods, this approach won't work. So we resort to indirection.

...End of Excerpt. Please purchase the magazine to read the full article.