tags:

views:

266

answers:

1

I want to reset the "checked" property of all TAction objects of a ribbon to false when clicking on any ribbon button and then only set it true on the pressed button. But I did not yet find a way to access all the "checked" properties of the ActionManager's Actions. I think I need to loop through the actionmanager's actionlist... however, but I did not yet find the right way to do. I'd be very glad if someone could give me some hint on this.

Thanks!

+2  A: 

TActionManager descends from TCustomActionList, so whatever you can do with the latter, you can do with the former. It has two properties you'll need to use, Actions, which is the array property that gives you access to all the list's actions, and ActionCount, which tells you how many there are. Use them to write an ordinary loop, like this:

var
  i: Integer;
  Contained: TContainedAction;
  Action: TCustomAction;
begin
  for i := 0 to Pred(ActionList.ActionCount) do begin
    Contained := ActionList[i]; // shorthand for ActionList.Actions[i]
    if not (Contained is TCustomAction) then
      continue; // Doesn't have Checked property

    Action := TCustomAction(Contained);
    Action.Checked := False;
  end;
end;

Action lists can hold lots of kinds of actions, and they don't all have Checked properties. That property is introduced in TCustomAction, so the code above also filters out the things that don't descend from that class.

Rob Kennedy
Though rob solved my specific question another way, this answer is also very helpful for understanding how all this action stuff works.Thanks!