Results 1 to 9 of 9

Thread: [RESOLVED] access object in a form

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2006
    Location
    /root/usr/local/bin
    Posts
    476

    Resolved [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

  2. #2
    Fanatic Member
    Join Date
    Jan 2005
    Location
    Cebu
    Posts
    607

    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.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2006
    Location
    /root/usr/local/bin
    Posts
    476

    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

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2006
    Location
    /root/usr/local/bin
    Posts
    476

    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.

  6. #6
    Fanatic Member
    Join Date
    Jan 2005
    Location
    Cebu
    Posts
    607

    Re: access object in a form

    He is. Here.

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2006
    Location
    /root/usr/local/bin
    Posts
    476

    Re: access object in a form

    where here?

  8. #8
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: access object in a form

    Quote Originally Posted by basti42
    where here?
    www.vbforums.com

  9. #9
    Hyperactive Member drattansingh's Avatar
    Join Date
    Sep 2005
    Posts
    395

    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
  •  



Click Here to Expand Forum to Full Width