Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Shared Variable VS Instance Variable

319 views
Skip to first unread message

大投菜與小唇唇

unread,
Apr 7, 2002, 8:40:58 AM4/7/02
to
Dear all,

I am a newbie to Powerbuilder. I have a question on the terms of Shared
Variable and Instance Variable. What are they? What's the difference between
them?

I have already looked for them in books and the Internet, but due to a lack
of examples, I can't figure them out clearly.

Please kindly advise me if possible. Thanks for you kind attention.

Best Regards,
Someone.


John Danielecki

unread,
Apr 9, 2002, 1:39:49 AM4/9/02
to
A shared variable is also called a class variable. There is one copy of it
that is shared by all instances of the class. On the other hand, instance
variables are just that; each instance of a class has it's own copy of the
instance variables declared in the class. I developed a PB library that
encapsulates all the Win32 common controls in Comctl32.dll. A function
within the dll, InitCommonControls, needs to be called once for each type of
control used in the application. Since I may use several toolbars in a
rebar control, I do not want to call InitCommonControls on the toolbar class
each time a toolbar instance is created. So I use a shared or class variable
to let me know if the toolbar class has already been initialized. Another
use for a class variable would be as an instance counter. In the
constructor for the base class the private shared variable is incremented
each time an instance of any sibling is instantiated. When the instance is
destroyed, the counter is decremented. This can be used to allocate and free
up resources used by a particular class. As for instance variables, each
instance of a class must keep it's own data because that data is unique. For
example, you create a name class with the instance variables firstName and
lastName. Since you have different names in your address book application,
you need to have each class keep it's own copy of the name, and NOT share
it; otherwise, they would all have the same firsName and lastName.

0 new messages