不论我添的是什么都提示我是对的,为什么啊??????function HasNum(s:string):bool;
var i:integer;
begin
 for i := 1 To Length(s) do
 if (s[i] >= '0') or (s[i] <= '9') or (s[i] = '+') then
 begin
 HasNum := True;
 Exit;
 end
 else
 begin
 HasNum := FALSE;
 end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
ss:string;
begin
     if ed_ydz.Text<>'' then   //&Ocirc;&acute;&micro;&Oslash;&Ouml;·*******
     ss:=ed_ydz.Text;
        if HasNum(ss) then
          begin
           MessageBox(0,正确·',MB_ICONERROR);
          end
          else
          begin
             MessageBox(0,错误,'&acute;í&Icirc;ó',MB_ICONERROR);
          end;
end;

解决方案 »

  1.   

    function HasNum(s:string):bool;
    var i:integer;
    begin
     for i := 1 To Length(s) do
     if (s[i] >= '0') or (s[i] <= '9') or (s[i] = '+') then
     begin
     HasNum := True;
     Exit;
     end
     else
     begin
     HasNum := FALSE;
     end;
    end;你这么循环,除非你传如的字符串中没有一个数字和+号才会返回false的。呵呵
      

  2.   

    if (s[i] >= '0') or (s[i] <= '9') or (s[i] = '+') then第一个or 改为and
                     
    if (s[i] >= '0') and (s[i] <= '9') or (s[i] = '+') then
      

  3.   

    当然不对了。function HasNum(s:string):bool;
    var i:integer;
    begin
     for i := 1 To Length(s) do
     if (s[i] >= '0') or (s[i] <= '9') or (s[i] = '+') then
     begin
     HasNum := True;
     Exit;
     end
     else
     begin
     HasNum := FALSE;
     Break;  //加这句
     end;
    end;
      

  4.   

    if (s[i] >= '0') or (s[i] <= '9') or (s[i] = '+') then 
      第一个or不对了,要改成and
    if (s[i] >= '0') and(s[i] <= '9') or (s[i] = '+') then function HasNum(s:string):bool;
    var i:integer;
    begin
     Result:=false;
     for i := 1 To Length(s) do
     if  s[i] in ['+','0'..'9'] then
     begin
     HasNum := True;
     Brake;
     end;
    end;
      

  5.   

    给你个例子
    procedure TForm1.Button2Click(Sender: TObject);
    var
      s: string;
    begin
      s:= '0099++a';
      if ss(s) then showmessage('true') else showmessage('false');
    end;function TForm1.ss(s: string): boolean;
    var
      i: integer;
      a: string;
    begin
      result:= true;
      for i:= 1 to length(s) do
      begin
        if not (s[i] in ['0'..'9','+']) then
        begin
          result:= false;
          break;
        end;
      end;
    end;
      

  6.   

    if ((s[i] >= '0') AND (s[i] <= '9')) or (s[i] = '+') then