var i:integer;
tmpStr:string;
begin
if key = VK_RETURN then
 begin
  tmpStr:=eschool.text;
  if tmpStr='' then
   beign
    showmessage('请输入学校名称!');
    exit;
   end; //end of if tmpStr
  for i:=1 to length(tmpStr) do
  if ((tmpStr[i]>'0') and (tmpStr[i]<'9')) then
   begin
    showmessage('请输入汉字!')
    jiguan.SetFocus;
    exit;
   end;  //end of if & for
end;

解决方案 »

  1.   

    是汉字....
    用var tmpStr:wideString; 更保险
      

  2.   

    按你的程序,判断的是Edit中是否含有1234567890这个数字,而不是任意数字,如果要判断是否是数字可以用FloattoStr或Inttostr如果没有出现EConvertError则为数字,否则是字符。
      

  3.   

    to  oracle_lover(数据库情人) :
    你的方法不行,提示if ((tmpStr[i]>'0') and (tmpStr[i]<'9')) then
    运行错误。
      

  4.   

    if (tmpStr[i] in ['0'..'9']) then
      

  5.   

    在keypress事件中添加如下语句:
    if (key not in ['0'..'9']) and (key<>#13) and (key<>#8)
    and (key<>#0) then exit;
      

  6.   

    我这里运行正常,应该是if ((tmpStr[i]>='0') and (tmpStr[i]<='9')) 不过eulb(执子之手,与子偕老)的方法更好
      

  7.   

    略------
    else 
     begin
      try
        strtofloat(eschool.Text);     //如果转换成功,则说明是数字
        ShowMessage('请输入汉字!');
        eschool.SetFocus;
        except
        abort;
       end;
     end;
      

  8.   

    procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
    begin
    if (key<='9') and (key>='0') then
      begin
        key:=#0;
        showmessage('请输入汉字!');
        exit;
      end;
    end;