Setting TRadioButton to checked causes OnClick event

后端 未结 4 1344
陌清茗
陌清茗 2021-01-18 20:51
mybox.Checked := true;

Setting TRadioButton to checked (by code) causes OnClick event handler to be called.

How can I recognize if user is

4条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-18 21:25

    TRadioButton (like TCheckBox) provides a protected property ClicksDisabled that can help you.

    I use class helpers to add the needed functionality:

    RadioButton1.SetCheckedWithoutClick(False);
    

    with the following class helper for a VCL TRadioButton:

    TRadioButtonHelper = class helper for TRadioButton
        procedure SetCheckedWithoutClick(AChecked: Boolean);
    end;
    
    procedure TRadioButtonHelper.SetCheckedWithoutClick(AChecked: Boolean);
    begin
        ClicksDisabled := True;
        try
            Checked := AChecked;
        finally
            ClicksDisabled := False;
        end;
    end;
    

提交回复
热议问题