OnChanging not fired in TsRadioGroup

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #54325
    Support
    Keymaster

      This event is intended for user actions now, clicking or buttons pressing.

      Do you think, it's required for changing by code also?

      #54337
      HeDiBo
      Participant
        'Support' wrote:

        This event is intended for user actions now, clicking or buttons pressing.

        Do you think, it's required for changing by code also?

        Absolutely. Check TcxRadioGroup of Develeoper Express. It will generate the event when ItemIndex is changed in code. That's what you want.

        Thanks.

        #54354
        Support
        Keymaster
          'HeDiBo' wrote:
          Absolutely. Check TcxRadioGroup of Develeoper Express. It will generate the event when ItemIndex is changed in code. That's what you want.

          Maybe you mean the OnChange event? OnChange and OnChanging has different behaviours..

          #54356
          HeDiBo
          Participant
            'Support' wrote:

            Maybe you mean the OnChange event? OnChange and OnChanging has different behaviours..

            No. I meant OnChanging. TsRadioGroup does not have an OnChange event (in TcxRadioGroup it's the other way around)..

            The difference between the two is very subtle. In the OnChanging event you can still cancel the change, where in OnChange the change has already been done. If you can have only one of those, I would opt for OnChanging, because it has more possibilities.

            Have a look at this code snippet:

            Code:
            procedure TForm.rgChanging( Sender: TObject; NewIndex: Integer; var AllowChange: Boolean );
            begin
            sButton.Enabled := NewIndex >= 0;
            end;

            So to disable sButton, I would set ItemIndex to -1 in my code. The way it is now, that's not possible without an extra procedure.

            In general, events that are caused by a user action, should also be fired if the same action is performed in the code. I know of hardly any exceptions to this rule.

            #54357
            Support
            Keymaster

              Standard way in this situation is using of the OnClick event.

              OnChanging occurs before changing of component, OnClick occurs after changing, look what I found in the help:

              Description

              Use the OnClick event handler to respond when the user clicks the control. If the control has an associated action, and that action has an OnExecute method, the action's OnExecute method responds to click events unless it is superseded by an OnClick event handler.

              Usually OnClick occurs when the user presses and releases the left mouse button with the mouse pointer over the control. This event can also occur when:

              The user selects an item in a grid, outline, list, or combo box by pressing an arrow key.

              The user presses Spacebar while a button or check box has focus.

              The user presses Enter when the active form has a default button (specified by the Default property).

              The user presses Esc when the active form has a cancel button (specified by the Cancel property).

              The user presses the accelerator key for a button or check box. For example, if the value of the Caption property of a check box is '&Bold', the B is underlined at runtime and the OnClick event of the check box is triggered when the user presses Alt+B.

              The Checked property of a radio button is set to true.

              The value of the Checked property of a check box is changed.

              #54360
              HeDiBo
              Participant
                'Support' wrote:

                Standard way in this situation is using of the OnClick event.

                OnChanging occurs before changing of component, OnClick occurs after changing

                You did not react to my example. If you look carefully, you will find that OnClick will not work in case ItemIndex is set to -1.

                #54369
                HeDiBo
                Participant

                  In AC 10.21 you decided to implement both OnChange and OnChanging:

                  • OnChange is implemented such, that a compiler warning is issued about overriding the private property FOnChange.[*]If ItemIndex is set by code, OnChange is called, but OnChanging is not called.[*]If ItemIndex is set by the user, OnChanging is called, but OnChange is not called.

                  I'm sorry, It's a mess now :wacko:

                  #54388
                  Support
                  Keymaster

                    Sorry, it's my fault and I have found the reason of the problem.

                    I can send you the patched file where the OnChange property works, if you wish to try it now.

                    #54394
                    HeDiBo
                    Participant
                      'Support' wrote:

                      Sorry, it's my fault and I have found the reason of the problem.

                      I can send you the patched file where the OnChange property works, if you wish to try it now.

                      That's OK. I'll await the new release. I've made some code to avoid it.

                      #54461
                      HeDiBo
                      Participant
                        'Support' wrote:

                        Sorry, it's my fault and I have found the reason of the problem.

                        I can send you the patched file where the OnChange property works, if you wish to try it now.

                        In 10.22 OnChange works properly. I still think that OnChanging should be called too when ItemIndex is set by code.

                      Viewing 10 posts - 1 through 10 (of 10 total)
                      • You must be logged in to reply to this topic.