|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Global objectsMain 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 which corresponds with 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 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.)? "BobRoyAce" <b***@omegasoftwareinc.com> a écrit dans le message de news: 1150004035.630934.229***@c74g2000cwc.googlegroups.com...| Is there a way to do this? I guess my question, more generally, is how The answer is similar to that for your other question about a login form.| 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.)? Don't rely on your main form as a place to do anyhting apart from manage your main form. Create "global" objects in your program code module; you will then need to, either pass the object to any forms that you create or add static properties/methods to a non-instantiable class that is visible throughout your application. Joanna -- Joanna Carter [TeamB] Consultant Software Engineer Thanks Joanna...
Which program code module do I create these "global" objects in? How do I declare them? When and how does the code that instantiates them get executed? How do I "pass the object" to any forms, etc.? Could you post a very simple code sample? "BobRoyAce" <b***@omegasoftwareinc.com> a écrit dans le message de news: 1150037008.526118.247***@h76g2000cwa.googlegroups.com...| Which program code module do I create these "global" objects in? How do Create yourself a new code module and give it the same namespace as the rest | I declare them? When and how does the code that instantiates them get | executed? How do I "pass the object" to any forms, etc.? Could you post | a very simple code sample? of your application. // Globals.cs namespace MyCompany.MyProject { public static class Globals { private MyClass myObject = new MyClass(); public static MyClass MyObject { get { return myObject; } set { myObject = value; } } } } This will be accessible from any other module in your project. { MyClass test = Globals.MyObject; ... // or ... Globals.MyObject.SomeProperty = someValue; Globals.MyObject.SomeMethod(); ... // etc } Joanna -- Joanna Carter [TeamB] Consultant Software Engineer Thanks Joanna...
I don't seem to be able to use the Static keyword in VB. Is there an equivalent way to declare the class as Static in VB? Also, by the way, would this be the same place that I would put the Main procedure you mentioned in your answer to my Login post? What happens if I have a Main procedure in my Main form as well? Joanna Carter [TeamB] wrote: Show quote > "BobRoyAce" <b***@omegasoftwareinc.com> a écrit dans le message de news: > 1150037008.526118.247***@h76g2000cwa.googlegroups.com... > > | Which program code module do I create these "global" objects in? How do > | I declare them? When and how does the code that instantiates them get > | executed? How do I "pass the object" to any forms, etc.? Could you post > | a very simple code sample? > > Create yourself a new code module and give it the same namespace as the rest > of your application. > > // Globals.cs > > namespace MyCompany.MyProject > { > public static class Globals > { > private MyClass myObject = new MyClass(); > > public static MyClass MyObject > { > get { return myObject; } > set { myObject = value; } > } > } > } > > This will be accessible from any other module in your project. > > { > MyClass test = Globals.MyObject; > ... > // or > ... > Globals.MyObject.SomeProperty = someValue; > Globals.MyObject.SomeMethod(); > ... // etc > } > > Joanna > > -- > Joanna Carter [TeamB] > Consultant Software Engineer "BobRoyAce" <b***@omegasoftwareinc.com> a écrit dans le message de news: 1150061554.326419.90***@c74g2000cwc.googlegroups.com...| I don't seem to be able to use the Static keyword in VB. Is there an I believe the VB equivalent of static is shared.| equivalent way to declare the class as Static in VB? As to whether you can have a static class in VB, I am sorry, I don't know how to use VB at all well. If you cannot have a shared class, then you need to have a Sigleton class with a hidden constructor and an instance method. If you need to know how to do this, then you would be better asking in a VB language group. | Also, by the way, would this be the same place that I would put the You really shouldn't have a Main procedure in a form class, it should be in | Main procedure you mentioned in your answer to my Login post? What | happens if I have a Main procedure in my Main form as well? a separate module. I would create a separate module for the Main and another for the globals. Joanna -- Joanna Carter [TeamB] Consultant Software Engineer |
|||||||||||||||||||||||