Access to arraylist globaly
-
Hi there, How do i make an arraylist available globaly. I know that the easy way is to make it a (Dare I say it :)) Global variable.:omg:
-
Hi there, How do i make an arraylist available globaly. I know that the easy way is to make it a (Dare I say it :)) Global variable.:omg:
-
you can make the variable shared within a class public class Common public shared oaArray as new arraylist end class ----- any code: common.oarraylist.add("??????")
Thanks for that.:):cool:
-
Hi there, How do i make an arraylist available globaly. I know that the easy way is to make it a (Dare I say it :)) Global variable.:omg:
A global variable is the only way to make it available 'globally'. A better choice is to say 'who needs to see this, and in what context'. For example, can you pass it to the intended clients via a delegate ?
Christian Graus - C++ MVP 'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
-
A global variable is the only way to make it available 'globally'. A better choice is to say 'who needs to see this, and in what context'. For example, can you pass it to the intended clients via a delegate ?
Christian Graus - C++ MVP 'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
-
Christain, using 'shared' will also make it available globally to the project and within referenced objects.
Of course it will - the point is, he knows it's a bad idea, so why not talk about alternatives ?
Christian Graus - C++ MVP 'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
-
A global variable is the only way to make it available 'globally'. A better choice is to say 'who needs to see this, and in what context'. For example, can you pass it to the intended clients via a delegate ?
Christian Graus - C++ MVP 'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
A global variable is the only way to make it available 'globally'. A better choice is to say 'who needs to see this, and in what context'. For example, can you pass it to the intended clients via a delegate posted by Christian Graus - C+++ MVP This is a good question:) I have had a look and 8 out of 27 procedures need to see my Global Var.BTW I have put 3 more in there.:):omg: 1 is a arraylist 1 is a string 2 are int. A little info. my application is a image viewing program, i ask the user to select the directory that they want to view...put the dir listing into a string and put the image names into the array. The rest of the program deals with displaying the images by clicking on verious menu's & buttons. Which is why i need global var. I split up the directory listing and display that if the user want too. if there is an easier way to do this, i am open to ideas....just remember i am a newbie to VB2005 programming:-O
-
A global variable is the only way to make it available 'globally'. A better choice is to say 'who needs to see this, and in what context'. For example, can you pass it to the intended clients via a delegate posted by Christian Graus - C+++ MVP This is a good question:) I have had a look and 8 out of 27 procedures need to see my Global Var.BTW I have put 3 more in there.:):omg: 1 is a arraylist 1 is a string 2 are int. A little info. my application is a image viewing program, i ask the user to select the directory that they want to view...put the dir listing into a string and put the image names into the array. The rest of the program deals with displaying the images by clicking on verious menu's & buttons. Which is why i need global var. I split up the directory listing and display that if the user want too. if there is an easier way to do this, i am open to ideas....just remember i am a newbie to VB2005 programming:-O
Christian, I don't claim to know it all so please teach me, I'm curious: A delegate is a more or less a memory pointer to some routine. Given that, how would a delegate help? How does the delegate "expose" the arraylist variable? You would need to call a routine for adding or removing or searching, or returning the arraylist itself, etc. With all of that needed functionality could one single pointer give the developer that? You can't overload a delegate can you? Also, I would need to pass the pointer to every object that needed it which may or may not possible depending on how the object was created. Thanks, Nathan
-
Christian, I don't claim to know it all so please teach me, I'm curious: A delegate is a more or less a memory pointer to some routine. Given that, how would a delegate help? How does the delegate "expose" the arraylist variable? You would need to call a routine for adding or removing or searching, or returning the arraylist itself, etc. With all of that needed functionality could one single pointer give the developer that? You can't overload a delegate can you? Also, I would need to pass the pointer to every object that needed it which may or may not possible depending on how the object was created. Thanks, Nathan
nlarson11 wrote:
Given that, how would a delegate help?
Because a global variable is essentialy the easy solution to the question 'how do I make this visible in more than one place', when often the real question is 'when my classes data is updated, I need to let some clients know about it'. As such, you can define an event, such as 'ImageListUpdated', which passes the list directly to the clients that subscribe to it. This means that the access to the information is one way, and rigidly defined in terms of when it occurs.
nlarson11 wrote:
You can't overload a delegate can you?
More than one client can subscribe to an event, so even if three classes need the message, it is not a big deal
nlarson11 wrote:
Also, I would need to pass the pointer to every object that needed it which may or may not possible depending on how the object was created.
When would that not be possible ? How is it different to having it exposed on a global, in that regard ?
Christian Graus - C++ MVP 'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
-
nlarson11 wrote:
Given that, how would a delegate help?
Because a global variable is essentialy the easy solution to the question 'how do I make this visible in more than one place', when often the real question is 'when my classes data is updated, I need to let some clients know about it'. As such, you can define an event, such as 'ImageListUpdated', which passes the list directly to the clients that subscribe to it. This means that the access to the information is one way, and rigidly defined in terms of when it occurs.
nlarson11 wrote:
You can't overload a delegate can you?
More than one client can subscribe to an event, so even if three classes need the message, it is not a big deal
nlarson11 wrote:
Also, I would need to pass the pointer to every object that needed it which may or may not possible depending on how the object was created.
When would that not be possible ? How is it different to having it exposed on a global, in that regard ?
Christian Graus - C++ MVP 'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
Another excellent reponce Christian:) I don't need to define an event as the event is allready happening when the user selected the directory to view the images from. The images are on the users computer, all i'm doing is getting their path\file names. The problem comes when the user wants to flip though the images as this is a seperate event. At the moment this is not a problem,as I'm using Public Shared var. (See I did not use the word Global):):) a question.... how much time & memory would it take to load into a imagelist 300+ images, of course some of the images could be different sizes, which then rules out using Imagelist. Myself I have a directory which contains images of different sizes, and i'm sure other users would be the same. So I don't think that I'll be using Imagelist any time soon.;P
-
Another excellent reponce Christian:) I don't need to define an event as the event is allready happening when the user selected the directory to view the images from. The images are on the users computer, all i'm doing is getting their path\file names. The problem comes when the user wants to flip though the images as this is a seperate event. At the moment this is not a problem,as I'm using Public Shared var. (See I did not use the word Global):):) a question.... how much time & memory would it take to load into a imagelist 300+ images, of course some of the images could be different sizes, which then rules out using Imagelist. Myself I have a directory which contains images of different sizes, and i'm sure other users would be the same. So I don't think that I'll be using Imagelist any time soon.;P
WestSideRailways wrote:
how much time & memory would it take to load into a imagelist 300+ images
I"m not sure, but the images themselves are passed by ref, so I wouldn't expect it to be much I'd just put them in a List if I had to pass them around.
Christian Graus - C++ MVP 'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert