|
-
May 11th, 2005, 10:02 AM
#1
Forms scope (resolved)
Hi all,
I am having difficulties with form scope in my project. I have a main form that spawns a few indentical children form's (I use the term children loosely as the main form is not MDI.) The main form also spawns 2 forms ("Global1" and "Global2") that need to be accessed by the children and in some cases forms spawned by the children (grandchildren) and forms spawned by them (great grand children.) Each of the children counld reside in sepparate class libraries. My question is about setting a refence to the Global forms. If I invoke the Global form at the top of Mainfrm like this
VB Code:
Public Class Mainfrm
Inherits System.Windows.Forms.Form
Public GlobalOptions As New Systems_Class.GlobalOptionsStruct
Public StrategyManager As Strategies.ManageStrategiesfrm
do I need to continually pass a Mainfrm reference to every subsequent child, grand child and great grandchild, or is there a way to declare the global forms globally and avoid the references
Any input will be appreciated
thanks
kevin
Last edited by kebo; May 12th, 2005 at 08:20 AM.
Process control doesn't give you good quality, it gives you consistent quality.
Good quality comes from consistently doing the right things.
Vague general questions have vague general answers. A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.
______________________________ Last edited by kebo : Now. Reason: superfluous typo's
-
May 11th, 2005, 10:22 AM
#2
Addicted Member
Re: Forms scope
If I'm understanding you correctly, you've got a Main form ("MainForm"), which is your project's startup object. You then have two other forms ("GlobalForm1" and "GlobalForm2"), which are created by MainForm. These other forms alos need to be accessible anywhere in the project.
I think you should be able to access those forms as public members of the MainForm.
In MainForm...
VB Code:
Public Global1 as New GlobalForm1
Public Global2 as New GlobalForm2
...then, from anywhere else in the project, you should be able to...
VB Code:
Dim MyString as String
MyString = MainForm.Global1.Text
-
May 11th, 2005, 10:40 AM
#3
Re: Forms scope
If you truly want them globally, I would put them in a module outside of any of the form classes. Form classes are much like any other class, but not entirely. You should be able to reference a Public member of a form class via the instance of that class:
dim frm1 as New Form1
All public members of Form1 should be visible as:
frm1.Member
My usual boring signature: Nothing
 
-
May 11th, 2005, 10:42 AM
#4
Re: Forms scope
Well, I got called away in the middle of typing that. I figured somebody would have jumped on it by now.
I just wanted to say that members of form classes don't seem to be quite the same as members of other classes. You might want to declare the global forms Public in a module rather than a form class, but I am not certain that it will make a difference if you just put them in a form class.
My usual boring signature: Nothing
 
-
May 11th, 2005, 10:45 AM
#5
Re: Forms scope
That is how I am declaring the globals, but the other forms in the project that reside in sepparate class libraries don't have a reference to Mainfrm, so just doing
...then, from anywhere else in the project, you should be able to...
VB Code:
Dim MyString as String
MyString = MainForm.Global1.Text
doesn't work. I also can't set a reference to Mainfrm at design time because it is the startup, not a dll.
kevin
Last edited by kebo; May 11th, 2005 at 10:59 AM.
Process control doesn't give you good quality, it gives you consistent quality.
Good quality comes from consistently doing the right things.
Vague general questions have vague general answers. A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.
______________________________ Last edited by kebo : Now. Reason: superfluous typo's
-
May 11th, 2005, 10:59 AM
#6
Re: Forms scope
 Originally Posted by Shaggy Hiker
If you truly want them globally, I would put them in a module outside of any of the form classes. Form classes are much like any other class, but not entirely. You should be able to reference a Public member of a form class via the instance of that class:
dim frm1 as New Form1
All public members of Form1 should be visible as:
frm1.Member
That's true if if frm1 is visible, which it is not to any of the forms in class libraries unless I pass a reference to it. What I am trying to avoid is pass a reference to each and every form that is in a class lib.
kevin
Process control doesn't give you good quality, it gives you consistent quality.
Good quality comes from consistently doing the right things.
Vague general questions have vague general answers. A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.
______________________________ Last edited by kebo : Now. Reason: superfluous typo's
-
May 11th, 2005, 11:12 AM
#7
Re: Forms scope
You're right, I misunderstood the original question
You have a bunch of forms in one or more class libraries. Some forms need access to items on another form. Therefore, the source form must be in scope of the destination forms. However, an instance of the source form may not be visible to the destination forms (unless you pass it to them).
That's a tough one. One way that would work in SOME circumstances would be to make the items on the source form Public Shared. This would mean that they are not tied to an instance, but are available for all to use. This could be REALLY bad, though. Only one instance of these items would exist for ALL instances of the form.
The other way for one class to be within the scope of another class, is for the first class to be defined within the second class. I just posted a thread on this yesterday. It works with forms, but you can't alter the contained form once it has been put in the outer form, and you could never create the inner form except within the outer form.
Other than that, I can't think of a good way to do this...though this odd thought just popped up, ugly as it is:
Make a class in the library that holds instances of all the different forms. As you create a new instance of any of the forms, add it to the class. The form in the library would be able to access the instance of the form in the class, but could not be sure that the instance was valid.
My usual boring signature: Nothing
 
-
May 12th, 2005, 08:20 AM
#8
Re: Forms scope
hey thanks for that Shaggy,
My resolutions was actually quite simple. I moved the main form into a new class lib, that way other class lib.s can see it. Now the only thing in the startup project is sub main which runs the main form, and nothing needs to refernce anything in the startup project
thanks again
kevin
Process control doesn't give you good quality, it gives you consistent quality.
Good quality comes from consistently doing the right things.
Vague general questions have vague general answers. A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.
______________________________ Last edited by kebo : Now. Reason: superfluous typo's
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|