Re: "Global" objects

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



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?





.



Relevant Pages

  • Re: "Global" objects
    ... The Controls in the form are also members of the form. ... the form created from the "main form" you just reference the field or ... private Form2 _Form2; ... have a main form on which I show various user controls depending on ...
    (microsoft.public.dotnet.framework.windowsforms)
  • Re: Q: global variable
    ... The life span of a variable is as long as the class instance it is ... We typically don't hold a reference to a Page ... A static field ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: An object-oriented network DBMS from relational DBMS point of view
    ... The sentence has a context, it presumes a memory model, you can point ... "A class instance is explicitly created by a class instance creation ... In the context of the Java memory model, you need a reference to them ...
    (comp.databases.theory)
  • Re: Run-time error 91: Object variable or With block variable no
    ... I only have one EXE and it, along with a DLL, are the projects having this ... In looking through the various user controls, ... > Then the reference in the top UserControl to the daughter Usercontrol ...
    (microsoft.public.vb.general.discussion)
  • Re: How to Clone a class instance
    ... > Could anyone show me how to clone a class instance without writing code to ... contained objects), with some of them reference counted, blind memory ... instance1 is already a typed pointer (usually referred to as a "reference") ...
    (borland.public.delphi.language.objectpascal)