Buttons switches in Delphi I have an action on four buttons. I need to make a down (checked) button if it's pressed and other buttons up (unchecked). My button is TToolButton and the property Style is set to tbsCheck.

Could you please suggest improvements?

LButtonName := (Sender as TAction).ActionComponent.Name;
   if LButtonName.Equals('btnVorigeWeek') then
      begin
        LSelectionType := 2;
        btnHuidigeWeek.Down := False;
        btnVorigeWeek.Down := True;
        btnHuidigeMaand.Down := False;
        btnVorigeMaand.Down := False;
      end
      else if LButtonName.Equals('btnHuidigeMaand') then
      begin
        LSelectionType := 3;
        btnHuidigeWeek.Down := False;
        btnVorigeWeek.Down := False;
        btnHuidigeMaand.Down := True;
        btnVorigeMaand.Down := False;
      end
      else if LButtonName.Equals('btnVorigeMaand') then
      begin
        LSelectionType := 4;
        btnHuidigeWeek.Down := False;
        btnVorigeWeek.Down := False;
        btnHuidigeMaand.Down := False;
        btnVorigeMaand.Down := True;
      end
      else
      begin
        LSelectionType := 1;
        btnHuidigeWeek.Down := True;
        btnVorigeWeek.Down := False;
        btnHuidigeMaand.Down := False;
        btnVorigeMaand.Down := False;
      end;
It seems I found better solution. All these buttons are located on ToolBar.

I can loop through the ToolBar and utilize the Name property on the buttons to compare with. So, I've changed it to:

  var
    LSelectionType, i: Integer;
    LButtonName: string;
  begin
    LSelectionType := 1;
    LButtonName := (Sender as TAction).ActionComponent.Name;    
    for i := 0 to ToolBar.ButtonCount -1 do
    begin
      ToolBar.Buttons[i].Down := (ToolBar.Buttons[i].Name = LButtonName);
      if ToolBar.Buttons[i].Down then
        LSelectionType := i + 1;
    end;
    ...
  end;


UPDATE

Finally, I set proper Tag property and set property Grouped to True for buttons and changed code:

  var
    LSelectionType: Integer;
    LActionComponent: TComponent;
  begin
    LSelectionType := 1;
    LActionComponent := (Sender as TAction).ActionComponent;

    if LActionComponent is TToolButton then
    begin
      (LActionComponent as TToolButton).Down := True;
      LSelectionType := (LActionComponent as TToolButton).Tag;
    end;
    // and using LSelectionType 
    ....
  end;