数据表中的字段‘zllx'类型是char(1),可能的值是0,1,2,[a-z]case DataModule1.zlzl_ADOQuery.fieldbyname('zllx').Asstring of
    0 :  RzRadioButton1.Checked:=true;
    1 :  RzRadioButton2.Checked:=true;
    2 :  RzRadioButton4.Checked:=true;
   else
    RzRadioButton3.Checked:=true;
end;
运行时,这个代码报错。
如果,运行这段程序
case DataModule1.zlzl_ADOQuery.fieldbyname('zllx').AsInteger of
    0 :  RzRadioButton1.Checked:=true;
    1 :  RzRadioButton2.Checked:=true;
    2 :  RzRadioButton4.Checked:=true;
   else
    RzRadioButton3.Checked:=true;
end;
当遇到‘zllx’的值为[a-z]时,肯定报类型错误报告!请高手指教,谢谢!

解决方案 »

  1.   

    字符串是不能作为case的条件的,这样:var 
      s: String;
      c: char;s := Trim(DataModule1.zlzl_ADOQuery.fieldbyname('zllx').Asstring);
    c := '';
    if (s <> '') then c := s[1];
    case c of
        '0' :  RzRadioButton1.Checked:=true;
        '1' :  RzRadioButton2.Checked:=true;
    .....
      

  2.   

    c := ''; 改为 c := chr(0);
      

  3.   

    case DataModule1.zlzl_ADOQuery.fieldbyname('zllx').Asstring[1] of
        '0' :  RzRadioButton1.Checked:=true;
        '1' :  RzRadioButton2.Checked:=true;
        '2' :  RzRadioButton4.Checked:=true;
       else
        RzRadioButton3.Checked:=true;
    end;
      

  4.   

    li_zhifu(东北人) 你的可以通过运行,但是不知道Asstring[1] 是什么意思? hthunter(核桃-我的心在下雨,雨中我和她携手漫步) ,我这个字段是不允许为空的谢谢你们!
      

  5.   

    Asstring返回一个字符串,用[1]获得第一个字符