In Delphi XE7, I use this trick to automatically enable or disable a toolbar button ("Edit ListView Item") according to whether an item in the ListView is selected or not, to prevent the user to click on the button if there is no ListView Item selected:
- Put a TActionList on a VCL Form.
- In the ActionList create an action
actTest. - Put a TButton on the form.
- Assign the action
actTestto the button. - Put a TListView on the form.
- In the ListView create two items.
In the
OnUpdateevent of theactTestaction write:procedure TForm1.actTestUpdate(Sender: TObject); begin actTest.Enabled := ListView1.SelCount > 0; CodeSite.Send('actTestUpdate'); // gets fired very often! end;
Now you can see that the button becomes enabled or disabled according to whether an item in the ListView is selected or not, independently from whether you select/deselect items with the mouse or with the keyboard or programmatically.
However, in the CodeSite Live Viewer I can see that the actTestUpdate event is fired continuously and very often, so the statement actTest.Enabled := ListView1.SelCount > 0; gets executed VERY OFTEN.
So my question is: Does this degrade the performance? If yes, is there another trick to achieve the above purpose?
The Action update events are (mostly) executed inside Application.Idle. As long as you don't do time critical things inside the event handlers there should be no noticeable performance degradation.