Suppress an event?

  1. 4 weeks ago

    Is there a simple way to suppress an event from firing when changing the value of a control? Specifically I have an Action event handler attached to a Checkbox, but I'd like to avoid running the handler when I initialize the value of the checkbox.

  2. Kem T

    Nov 15 Pre-Release Testers, Xojo Pro, XDC Speakers New York

    Usually you would do that by setting a flag somewhere and checking that flag in the event.

  3. Tim S

    Nov 15 Canterbury, UK

    I suppose one could argue that this is a design error, having an event fire when a control's value is changed in code. IIRC, this doesn't happen in javascript. I too have resorted to flags to avoid such events. But I'm not advocating changing that since there may for all I know be apps that rely on it. Are there any obvious use cases for having an event fire when the value is changed in code?

  4. Dave S

    Nov 15 San Diego, California USA

    One major case in point (and this bit me big time the other day).... and its really kind of not even a "event" by the standard definition.

    But Computed Property SETTERS will fire prior to the OPEN event. This causes all kinds of havoc if you have that setter update a control if the property changed... since that control may not even exist during the initialization sequence. So I had to use a flag, that was ultimately set to TRUE in the ACTIVATE event....

  5. Beatrix W

    Nov 15 Pre-Release Testers Europe (Germany)

    In the open event do:

    isOpening = true
    'do you stuff
    isOpening = false

    In the value changed event do:

    if isOpening then return
    'do other stuff
  6. OK - at first I was thinking that would be complicated since I need to ensure that the flag is reset properly every time the value is changed programmatically, but I'll just create a setter method that handles the flag. Thanks all!

  7. Tim P

    Nov 15 Pre-Release Testers feedback://46303

    @Tim S I suppose one could argue that this is a design error, having an event fire when a control's value is changed in code.

    There are some things that you'd want to evaluate on a control value change whether it was by user or by code. An event should always fire for predictability and reliability. It is on the developer to decide whether or not they need to evaluate anything in the event. If you don't need it, exit early like Kem and Beatrix suggest.

or Sign Up to reply!