Re: "Global" objects
- From: "Kevin Spencer" <kevin@xxxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Fri, 9 Jun 2006 08:40:31 -0400
He did not mention anything about being able to reference a class without a
reference to a class instance. In fact, static objects *do* require a
reference to a class (except for static classes). They do *not* require a
reference to an *instance* of a class. If you're thinking of VB Modules, the
reference is implied, and Modules are generally something to be avoided, put
there to make the transition to true object-orientation easier for VB6
developers, and tend to break object-orieted principles of encapsulation
when misused, which is often. Static objects are problematic, and should be
used very sparingly. In BobRoyAce's case, static objects are *not*
necessary, and should be avoided.
This is a simple matter of scope. By "global" he is referring to "global to
all objects within the Main Thread" which is a Form instance. All Form
members, and the objects contained in them are global to all other objects
in the Form, one way or another, unless they are declared as private or
protected to a class instance that they reside in (other than the Form
itself), such as in a Control inside another Control in the Form. The access
modifier is all that is needed to expose them to the rest of the objects in
the Form.
--
HTH,
Kevin Spencer
Microsoft MVP
Professional Chicken Salad Alchemist
A lifetime is made up of
Lots of short moments.
"Stoitcho Goutsev (100)" <100@xxxxxxx> wrote in message
news:eTyD0wviGHA.4512@xxxxxxxxxxxxxxxxxxxxxxx
BobRoyAce,
If you need methods, properties, events, etc accesible from anywhere
without the requirement to have a reference to an object that you need to
declare these memebers as static. When a member is static it can be
accessed by prefixing the member name with the type name e.g.
MyType.MyProperty.
--
HTH
Stoitcho Goutsev (100)
"BobRoyAce" <broy@xxxxxxxxxxxxxxxxxxxx> wrote in message
news:1149747279.902628.84260@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
I am new to .NET and am wondering how to accomplish having certain
global objects that could be referenced by other forms/user controls. I
have a main form on which I show various user controls depending on
which item the user clicks on in the NavBar on the left of the form.
Each user control has certain program functionality on it. What I want
to do, for example, is have certain object variables on the main form
(e.g. m_oEventLogger) that I can reference from my user controls, or
from other forms that I might show.
1) How do I declare these in the code for the Main form?
2) How would I refer to them from user controls shown on the main form?
3) How would I refer to them from other forms that are shown separate
from the main form?
.
- References:
- "Global" objects
- From: BobRoyAce
- "Global" objects
- Prev by Date: Re: "Global" objects
- Next by Date: New controls in .Net 2.0
- Previous by thread: Re: "Global" objects
- Next by thread: PropertyGrid MS .Net gurus opinion needed
- Index(es):
Relevant Pages
|