在Stringgrid里怎么判断客户输入的不是数字?然后返回要求从新输入?在STRINGGRID的第1列和第3列要这样要求,别的列没有要求.
因为如果客户输入的比如是'A'那么我的类型转换就会出错,'A'不能转换为integert或FLOAT,只有'1''2''3'才可以,很简单吧,但我不会做.

解决方案 »

  1.   

    procedure TForm1.StringGrid1SetEditText(Sender: TObject; ACol,
      ARow: Integer; const Value: String);
    begin
      if (ACol=1) or (ACol)=3 then  
      begin
      try
        strtoint(value)
      except
        showmessage('不正确');
      end;
      end;
    end;
      

  2.   

    那Try...except是什么意思,给讲一下,和其他判断语句有什么不同
      

  3.   

    同意,Try...except 是如果发生错误则执行Except ...end中的程序。没有则只执行 Try...Except中的语句
      

  4.   

    i,j:Integer
    val(str,i,j)
    if j=0 then showmessage(str是数字!)
      

  5.   

    procedure TForm1.StringGrid1SetEditText(Sender: TObject; ACol,
      ARow: Integer; const Value: String);
    var
          h : Integer;
    begin
          TryStrToInt('1' + Value, h);
          if Length(IntToStr(h)) < Length(Value) + 1 then
          begin
                ShowMessage('非法数据');
                StringGrid1.Cells[ARow, ACol] := Copy(Value, 1, Length(Value) - 1);
          end;
    end;
      

  6.   

    刀仔
    TryStrToInt有这个函数吗?
      

  7.   

    受教了。Delphi syntax:function TryStrToInt(const S: string; out Value: Integer): Boolean;DescriptionTryStrToInt converts the string S, which represents an integer-type number in either decimal or hexadecimal notation, into a number, which is assigned to Value. If S does not represent a valid number, TryStrToInt returns false; otherwise TryStrToInt returns true.
      

  8.   

    用这个,调试过的很好用
    procedure TForm1.StringGrid1KeyPress(Sender: TObject; var Key: Char);
    begin
      if (StringGrid1.Col=1) or (StringGrid1.Col=3) then
      begin
        if Not (Key in[#48..#57,#26,#27,#8,#9]) then
          Key:=#0;
      end;
    end;
    对于第一列和第三列如果输入的不是数字自动屏蔽掉,其他的列随便输入
    这样可以使程序流畅,如果搂主非得用showmessage(),那就自己在上面合适的地方加上吧,
    这应该很简单吧,呵呵