procedure TMainForm.AppMsgCBClick(Sender: TObject);
{ enables/disables proper radio button for checkbox click }
begin
  if EatMsgCB.Checked then
  begin
    with TRadioButton((Sender as TCheckBox).Tag) do
    begin
      Enabled := TCheckbox(Sender).Checked;
      if not Enabled then Checked := False;
    end;
  end;
end;
其中的TRadioButton((Sender as TCheckBox).Tag)是什么意思呢?为什么这样写?

解决方案 »

  1.   

    MainForm中的若干个CheckBox控件均指向AppMsgCBClick事件,它们的Tag属性存放的是相对应的RadioButton控件的地址,当点击这些CheckBox时,进入AppMsgCBClick事件,(Sender as TCheckBox)先转换成TCheckBox类型,再取它们的Tag值,TRadioButton((Sender as TCheckBox).Tag)再转换成TRadioButton类型,对相对应的RadioButton操作。