Setting TRadioButton to checked causes OnClick event

后端 未结 4 1315
陌清茗
陌清茗 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:08
     mybox.Tag := 666; 
     mybox.Checked :=true; 
     mybox.Tag := 0;
    
    procedure myboxOnclick(Sender : TObject);
    begin
    if Tag = 0 then
    //Do your thing
    end;
    
    0 讨论(0)
  • 2021-01-18 21:14

    If you have an action connected to the radiobutton, you can set the checked property of the action instead. This will also prevent the OnClick event to be fired.

    0 讨论(0)
  • 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;
    
    0 讨论(0)
  • 2021-01-18 21:26

    You can nil the OnClick event handler while changing a radiobutton state programmatically:

    procedure TForm1.Button6Click(Sender: TObject);
    var
      Save: TNotifyEvent;
    
    begin
      Save:= RadioButton2.OnClick;
      RadioButton2.OnClick:= nil;
      RadioButton2.Checked:= not RadioButton2.Checked;
      RadioButton2.OnClick:= Save;
    end;
    
    0 讨论(0)
提交回复
热议问题