我在Form上放上一个RadioGroup,又在其中放置5个RadioButton,
然后代码如下:procedure TForm1.RadioButton1Click(Sender: TObject);
var
  R:TRadioButton;
begin  case R.Tag of
    0:s:='A';
    1:s:='B';
    2:s:='C';
    3:s:='D';
    4:s:='E';
  end;
  ShowMessage(s);
  //ShowMessage(IntToStr(R.Tag));end;
然后将其他的RadioButton的Click指向他,当点击其他RadioButton时,消息框显示的还是A,但当ShowMessage(IntToStr(R.Tag));可用时,消息框又能正确地显示了。不知道是怎么回事啊?

解决方案 »

  1.   

    在begin后面加个
    r:=(Sender as TRadioButton);
      

  2.   

    procedure TForm1.RadioButton1Click(Sender: TObject);
    var
      R:TRadioButton;
    begin
      R:= Sender as TRadioButton;
      case R.Tag of
        0:s:='A';
        1:s:='B';
        2:s:='C';
        3:s:='D';
        4:s:='E';
      end;
      ShowMessage(s);
      //ShowMessage(IntToStr(R.Tag));end;
      

  3.   

    统一楼上的说法
    procedure TForm1.RadioButton1Click(Sender: TObject);
    var
      R:TRadioButton;
    begin
      R:= Sender as TRadioButton;
      case R.Tag of
        0:s:='A';
        1:s:='B';
        2:s:='C';
        3:s:='D';
        4:s:='E';
      end;
      ShowMessage(s);
      //ShowMessage(IntToStr(R.Tag));end;