469,343 Members | 5,723 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,343 developers. It's quick & easy.

"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 fkLastUpdatedByUserID 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.)?

Jun 12 '06 #1
4 1144
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" <br**@omegasoftwareinc.com> schreef in bericht
news:11*********************@i40g2000cwc.googlegro ups.com...
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 fkLastUpdatedByUserID 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.)?

Jun 12 '06 #2
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.

Jun 12 '06 #3
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.

Jun 12 '06 #4
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.text = TheClass.TheField

I hope this helps,

Cor

"BobRoyAce" <br**@omegasoftwareinc.com> schreef in bericht
news:11**********************@f6g2000cwb.googlegro ups.com...
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.

Jun 12 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Eddy Ilg | last post: by
9 posts views Thread by Javaman59 | last post: by
2 posts views Thread by Steve | last post: by
8 posts views Thread by Hans Greif | last post: by
1 post views Thread by CARIGAR | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.