OnClicked in OpionButton

Started by velasquez, August 28, 2015, 01:28:01 PM

Previous topic - Next topic

velasquez

Is there a way to know dcl-Control-GetValue an Option Button before completing onClicked event?

roy_043

I am not sure what you mean. But you do not need the Option Button's OnClick event to read its value.

velasquez

Quote from: roy_043 on August 28, 2015, 02:00:38 PM
I am not sure what you mean. But you do not need the Option Button's OnClick event to read its value.

An OptionButton does a great job when it is selected, yet a user clicks on it again, I want to prevent it do all the work without.

roy_043

You can quite easily use a stored value to prevent the execution of code inside an event handler. See the example below. Note: since the code more or less emulates the built-in functionality of an Option List, using that control may be more convenient for you.

Code (autolisp) Select
(defun c:YourCommand  (
                        / c:YourProject/Form1#OnInitialize
                          c:YourProject/Form1/OptionButton1#OnClicked
                          c:YourProject/Form1/OptionButton2#OnClicked
                          oldOption
                      )

  (defun c:YourProject/Form1#OnInitialize ()
    (setq oldOption
      (cond
        ((= 1 (dcl-Control-GetValue YourProject/Form1/OptionButton1))
          (dcl-Control-GetCaption YourProject/Form1/OptionButton1)
        )
        ((= 1 (dcl-Control-GetValue YourProject/Form1/OptionButton2))
          (dcl-Control-GetCaption YourProject/Form1/OptionButton2)
        )
        (T
          ""
        )
      )
    )
  )

  (defun c:YourProject/Form1/OptionButton1#OnClicked (value / caption)
    (setq caption (dcl-Control-GetCaption YourProject/Form1/OptionButton1))
    (if (/= oldOption caption)
      (progn
        (setq oldOption caption)
        (princ "\nDo your stuff 1 ... ")
      )
      (princ "\nDo nothing 1 ")
    )
  )

  (defun c:YourProject/Form1/OptionButton2#OnClicked (value / caption)
    (setq caption (dcl-Control-GetCaption YourProject/Form1/OptionButton2))
    (if (/= oldOption caption)
      (progn
        (setq oldOption caption)
        (princ "\nDo your stuff 2 ... ")
      )
      (princ "\nDo nothing 2 ")
    )
  )

  (setvar 'cmdecho 0)
  (command "_opendcl")
  (setvar 'cmdecho 1)
  (dcl-Project-Load "YourProject.odcl" T)
  (dcl-Form-Show YourProject/Form1)
  (princ)
)

velasquez

Quote from: roy_043 on August 29, 2015, 01:13:34 PM
You can quite easily use a stored value to prevent the execution of code inside an event handler. See the example below. Note: since the code more or less emulates the built-in functionality of an Option List, using that control may be more convenient for you.




Thank you roy