"Global" objects

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • BobRoyAce

    #1

    "Global" objects

    I posted the post below in another newsgroup and it has been suggested
    that this may be a better place to post it. See below:

    ---ORIGINAL POST BEGINS---
    I have an application which is comprised of, among many other things, a
    Main form which shows various user controls depending on which NavBar
    link they click on. In addition, there are many Entity classes that I
    created to support the application, one of which happens to be called
    User. In my main form I currently instantiate a User object which
    corresponds
    to the user who logged in. The User object that is created
    (g_oCurrentUser ) is declared as Private in my Main form's code, but
    there is a Public function (GetCurrentUser ) that returns a pointer to
    g_oCurrentUser.

    My question is "Is there a way for the other entity classes to "get at"
    the
    g_oCurrentUser object from the main form? The reason I need to do this
    is because I want to pull the current user's ID to use for populating
    the fkLastUpdatedBy UserID field of the entities when they have been
    changed by the current user.

    Is there a way to do this? I guess my question, more generally, is how
    can I have Object variables that are accessible both to the Main form
    and to other parts of the system (e.g. user controls that will be
    created later and shown on the form, other Objects, modules, etc.)?

  • Cor Ligthert [MVP]

    #2
    Re: "Global&qu ot; objects

    Bob,

    You can use a shared class or a module (which is a shared class with less
    documentive value).

    It this is not what you want or if you don't know how, than please reply.

    Cor

    "BobRoyAce" <broy@omegasoft wareinc.com> schreef in bericht
    news:1150082851 .379731.81830@i 40g2000cwc.goog legroups.com...[color=blue]
    >I posted the post below in another newsgroup and it has been suggested
    > that this may be a better place to post it. See below:
    >
    > ---ORIGINAL POST BEGINS---
    > I have an application which is comprised of, among many other things, a
    > Main form which shows various user controls depending on which NavBar
    > link they click on. In addition, there are many Entity classes that I
    > created to support the application, one of which happens to be called
    > User. In my main form I currently instantiate a User object which
    > corresponds
    > to the user who logged in. The User object that is created
    > (g_oCurrentUser ) is declared as Private in my Main form's code, but
    > there is a Public function (GetCurrentUser ) that returns a pointer to
    > g_oCurrentUser.
    >
    > My question is "Is there a way for the other entity classes to "get at"
    > the
    > g_oCurrentUser object from the main form? The reason I need to do this
    > is because I want to pull the current user's ID to use for populating
    > the fkLastUpdatedBy UserID field of the entities when they have been
    > changed by the current user.
    >
    > Is there a way to do this? I guess my question, more generally, is how
    > can I have Object variables that are accessible both to the Main form
    > and to other parts of the system (e.g. user controls that will be
    > created later and shown on the form, other Objects, modules, etc.)?
    >[/color]


    Comment

    • BobRoyAce

      #3
      Re: &quot;Global&qu ot; objects

      I don't know if that's what I need, but sounds like I would want one of
      them. I don't know how to do either, though, so would appreciate
      guidance including steps and code samples if at all possible (brief, of
      course). I am brand new to VB.NET and am using Visual Studio 2005.

      Comment

      • BobRoyAce

        #4
        Re: &quot;Global&qu ot; objects

        I don't know if that's what I need, but sounds like I would want one of
        them. I don't know how to do either, though, so would appreciate
        guidance including steps and code samples if at all possible (brief, of
        course). I am brand new to VB.NET and am using Visual Studio 2005.

        Comment

        • Cor Ligthert [MVP]

          #5
          Re: &quot;Global&qu ot; objects

          Bob,

          You would not place values or objects that is for your complete project in
          one UI (form)class as all classes could use it.

          Therefore is the Shared Class (in fact it is placed on the mainstack of the
          resulting endprogram, and therfore consumes constantly memory). In C
          languages the name for this was Static, this word however does not so good
          reflect the meaning, because the contents of everything is variable.
          Therefore in VBNet it is Shared.

          You can make this class as by instance below. (Just typed in so watch typos)

          Public Shared Class TheClass 'MyClass is a special word
          Private mTheField as String
          Public Property TheField as String
          Get
          Retunr mField
          End Get
          Set ............. I forever forget this text it is autotyped
          mField = value
          End Set
          End Class

          This you can use in everywhere in your project by instance the mainfrm

          me.Textbox1.tex t = TheClass.TheFie ld

          I hope this helps,

          Cor



          "BobRoyAce" <broy@omegasoft wareinc.com> schreef in bericht
          news:1150091206 .418178.141330@ f6g2000cwb.goog legroups.com...[color=blue]
          >I don't know if that's what I need, but sounds like I would want one of
          > them. I don't know how to do either, though, so would appreciate
          > guidance including steps and code samples if at all possible (brief, of
          > course). I am brand new to VB.NET and am using Visual Studio 2005.
          >[/color]


          Comment

          Working...