- This topic has 10 replies, 2 voices, and was last updated 8 years, 11 months ago by HeDiBo.
-
AuthorPosts
-
November 4, 2015 at 4:10 pm #36741HeDiBoParticipant
In a TsRadioGroup, when the ItemIndex is set programmatically, the OnChanging event should be fired.
This would not be to prevent the index from changing, but to act upon the new value.
For instance:
Code:procedure TForm1.rgChanging( Sender: TObject;
NewIndex: Integer;
var AllowChange: Boolean);
begin
Button1.Enabled := NewIndex >= 0;
end;November 16, 2015 at 8:23 am #54325SupportKeymasterThis event is intended for user actions now, clicking or buttons pressing.
Do you think, it's required for changing by code also?
November 16, 2015 at 5:02 pm #54337HeDiBoParticipant'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.
November 20, 2015 at 1:27 pm #54354SupportKeymaster'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..
November 20, 2015 at 2:22 pm #54356HeDiBoParticipant'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.
November 20, 2015 at 3:30 pm #54357SupportKeymasterStandard 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.
November 21, 2015 at 1:10 pm #54360HeDiBoParticipant'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.
November 23, 2015 at 3:00 pm #54369HeDiBoParticipantIn 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:
November 26, 2015 at 7:54 pm #54388SupportKeymasterSorry, 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.
November 27, 2015 at 4:58 pm #54394HeDiBoParticipant'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.
December 4, 2015 at 2:25 pm #54461HeDiBoParticipant'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.
-
AuthorPosts
- You must be logged in to reply to this topic.