CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Jul 2009
    Location
    (Presently) Bahrah S.A.
    Posts
    24

    [RESOLVED] Active Property Updates

    I’m looking for a good way to Bind a property of a control to an existing object property for automatic updating Without polling. The instance of the object and the instance of the control will be created AND associated at runtime. The object doesn’t have a property changed event. Anyone have any creative suggestions, please don’t say poll with a timer, that’s such a cludge.

  2. #2
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Active Property Updates

    Create a change event, then
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    Jul 2009
    Location
    (Presently) Bahrah S.A.
    Posts
    24

    Re: Active Property Updates

    DG,

    I hate to sound ignorant, but that's essentially what I'm asking, how exactly would I go about creating a change event for something that has no method of triggering said event.

    Are you talking about trapping messages for the control and creating an event routine to execute based on the receipt of a specific message?

    Just as an example, say I wanted to update my control property when the user changes the picture in an image control. There is no event associated with a Picture Change. This is just a hypothetical example, as in my actual application there are potentially a dozen or more different custom controls whose properties need to be set based on the value of their associated variables and the variable types differ from control/variable pair to control/variable pair. The values are constantly changing on the variables and the controls need to reflect the change visually in real-time. If I had a change event for the variable it would be a snap because I could do a property set every time the variable changed.

    External Process updates Variable(Object Property)
    Visual indicator (custom control) reflects a visual change based on a State Property.
    The external process can't communicate directly to the Control so the Control must read the Variable that the External Process is writing to in order to reflect a state change.

    I hope that makes sense.

  4. #4
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Active Property Updates

    Look up a Wrapper class.

    Also, look into VB.Net. It's a lot easier to create Wrapper Class Events
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  5. #5
    Join Date
    Jul 2009
    Location
    (Presently) Bahrah S.A.
    Posts
    24

    Re: Active Property Updates

    Ah yes, I know what a wrapper class is. In fact most of the custom controls in question, the ones that need the value bound are essentially wrapper controls. I had thought of doing that, but since the property I need to Bind to the control is a property of a an OPC Class object I'm not too sure about wrapping those classes. I've finally got all my OPC bugs ironed out and got good communication with my server, I hate to start tinkering with with them, I'm just not that good of a programmer. Worst case scenarlo I will use a timer based polling method on a form by form basis. But I'm wondering about trapping messages and routing through a custom event routine. What do you think?

  6. #6
    Join Date
    Jul 2009
    Location
    (Presently) Bahrah S.A.
    Posts
    24

    Re: Active Property Updates

    For the benefit of anyone following the thread, I'm posting an example project with a quick down an dirty wrapper class for an image control. The class provides a PictureChange event that I've used to set the picture property of an image control with. I also set the Image.Tag = to the Image filename.

    In this example you store the stdPicture object (long pointer) and the complete path and filename for the image in the properties of the class object, then rather than directly updating the image properties (picture, stretct, tag etc.) you set these for the Class object then use the change event to transfer the properties to the image control.
    Attached Files Attached Files

  7. #7
    Join Date
    Dec 2001
    Posts
    6,332

    Re: Active Property Updates

    It might help to know what sort of external process you're talking about. The more detail you can provide, the better the chances of getting useful suggestions.
    Please remember to rate the posts and threads that you find useful.
    How can something be both new and improved at the same time?

  8. #8
    Join Date
    Jul 2009
    Location
    (Presently) Bahrah S.A.
    Posts
    24

    Re: Active Property Updates

    WizBang in my previous post I mentioned that the variable was a property of an instance of an OPC class object. The external process is an OPC server providing real time values from an Industrial Programmable Logic Controller that is controlling a machine process. Although OPC is a bit finicky, I was actually able to modify the OPCItem Class and create a DataChanged Event. Now I just declare my Class Object WithEvents and I'm getting an event from the data change without having to poll.

    Thanks to everyone for the help and suggestions.

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

Featured