|
-
Mar 26th, 2007, 07:58 PM
#1
Thread Starter
Hyperactive Member
[RESOLVED] access object in a form
hello!
for example i have button1 in a form1
i created a class1, how can i access the button1 in the class1?
or i would disable the button1 using in the class1
tnx
-
Mar 26th, 2007, 09:22 PM
#2
Fanatic Member
Re: access object in a form
Expose it. This can be done with modifiers. But this might not be good. Just create a public method/property that operates the enable/disable of your Form1's button.
-
Mar 26th, 2007, 10:01 PM
#3
Thread Starter
Hyperactive Member
Re: access object in a form
how? could you give a concrete example
in vb if i'm in a module i'll just type this form1.button1.enabled=false
tnx
-
Mar 26th, 2007, 10:51 PM
#4
Re: access object in a form
A form is an object just like any other object. How do you access a property of an object? You assign the object to a variable and you get or set the property of that variable. Forms are no different.
Also like any other object, to access it you need a reference to it. Your class cannot simply get or set a property of some random object out of thin air, whether it's a form or anything else. It must first have a reference to the form. How doe sit get that reference? That's up to you and will be determined by your application design. Does the form create this class instance? If so then the form can pass the object a reference to itself.
OOP is exactly like the real world. You know I exist but you can't visit me if you don't have my address. I can give you my address, or someone I gave it to can give it to you, or you can get it from somewhere public that I put it, e.g. a phone directory. Now that you have my address you know where to go to visit me. OOP is exactly the same. A reference to an object is a nice way of saying its memory address. Without the form's address the class instance cannot access it. Either the form can passit to the class instance itself, or some other object that has it can pass it to the class instance, or else the class instance can get it from some public place that the form has put it. If you ever want to know how objects work in OOP just think about how they work in real life.
-
Mar 26th, 2007, 10:57 PM
#5
Thread Starter
Hyperactive Member
Re: access object in a form
your such a nice person, your look like my smart teacher
hope person like you would teach others too
tnx.
-
Mar 26th, 2007, 10:59 PM
#6
Fanatic Member
Re: access object in a form
He is. Here.
-
Mar 26th, 2007, 11:01 PM
#7
Thread Starter
Hyperactive Member
Re: access object in a form
-
Mar 28th, 2007, 08:03 AM
#8
Re: access object in a form
 Originally Posted by basti42
where here?
www.vbforums.com
-
Mar 28th, 2007, 09:46 AM
#9
Hyperactive Member
Re: access object in a form
did you get the solution? If yes, please set it to RESOLVED.
Jennifer.
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
|