Click to See Complete Forum and Search --> : [RESOLVED] access object in a form
basti42
Mar 26th, 2007, 07:58 PM
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
nebulom
Mar 26th, 2007, 09:22 PM
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.
basti42
Mar 26th, 2007, 10:01 PM
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
jmcilhinney
Mar 26th, 2007, 10:51 PM
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.
basti42
Mar 26th, 2007, 10:57 PM
your such a nice person, your look like my smart teacher
hope person like you would teach others too
tnx.
nebulom
Mar 26th, 2007, 10:59 PM
He is. :) Here.
basti42
Mar 26th, 2007, 11:01 PM
where here?
mendhak
Mar 28th, 2007, 08:03 AM
where here?
www.vbforums.com
JenniferBabe
Mar 28th, 2007, 09:46 AM
did you get the solution? If yes, please set it to RESOLVED.
Jennifer.
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.