By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,554 Members | 1,146 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,554 IT Pros & Developers. It's quick & easy.

How to make a value visible to anywhere in my app?

P: 2
Hi, I'm still getting my head around programming with classes and I'm confused about something.
A have a class member that's set when I create an object. But my application has several other classes that I want to be able to see the value of this member and the only way I can think of to do that is by passing the member value as a parameter for the other class function that I want to be able to see the value.

Is this the right way to do it? It doesn't look neat and if I have several values to be shared then my functions will start to have too many parameters.
Any advice?
Thanks a lot.
Nov 20 '06 #1
Share this Question
Share on Google+
4 Replies


100+
P: 1,646
Hi, I'm still getting my head around programming with classes and I'm confused about something.
A have a class member that's set when I create an object. But my application has several other classes that I want to be able to see the value of this member and the only way I can think of to do that is by passing the member value as a parameter for the other class function that I want to be able to see the value.

Is this the right way to do it? It doesn't look neat and if I have several values to be shared then my functions will start to have too many parameters.
Any advice?
Thanks a lot.
Hi. There are some things that you can do to make the value of this class member available to the rest of your app. However...
When you design a class it is important to think through encapsulation. If your other classes require this value then it seems logical that you should merge the classes together as they share functionality.

The value can be stored in a global variable but that will still present the same problems in having to pass it to your other objects and it destroys encapsulation.
Nov 20 '06 #2

P: 2
Hi. There are some things that you can do to make the value of this class member available to the rest of your app. However...
When you design a class it is important to think through encapsulation. If your other classes require this value then it seems logical that you should merge the classes together as they share functionality.

The value can be stored in a global variable but that will still present the same problems in having to pass it to your other objects and it destroys encapsulation.
That's what I thought. The value I want to share is a language attribute that will tell different procedures in my application to use "Bonjour" instead of "Hello", for example. So I created an object that stores all the terms in the language the user chose to use. All I want is for this object to be visible anywhere in my app. There's just too much funcitonality to merge in the same class I think.
Nov 20 '06 #3

100+
P: 267
That's what I thought. The value I want to share is a language attribute that will tell different procedures in my application to use "Bonjour" instead of "Hello", for example. So I created an object that stores all the terms in the language the user chose to use. All I want is for this object to be visible anywhere in my app. There's just too much funcitonality to merge in the same class I think.
hi

have you tried a res-file wihin your project?

call data from there with
something like:
Form1.Sample.Caption = LoadResString(20 + Var)
Nov 21 '06 #4

100+
P: 1,646
That's what I thought. The value I want to share is a language attribute that will tell different procedures in my application to use "Bonjour" instead of "Hello", for example. So I created an object that stores all the terms in the language the user chose to use. All I want is for this object to be visible anywhere in my app. There's just too much funcitonality to merge in the same class I think.
You will find plenty to read about this right here
Nov 21 '06 #5

Post your reply

Sign in to post your reply or Sign up for a free account.