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;
i,j:Integer val(str,i,j) if j=0 then showmessage(str是数字!)
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;
刀仔 TryStrToInt有这个函数吗?
受教了。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.
用这个,调试过的很好用 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(),那就自己在上面合适的地方加上吧, 这应该很简单吧,呵呵
ARow: Integer; const Value: String);
begin
if (ACol=1) or (ACol)=3 then
begin
try
strtoint(value)
except
showmessage('不正确');
end;
end;
end;
val(str,i,j)
if j=0 then showmessage(str是数字!)
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;
TryStrToInt有这个函数吗?
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(),那就自己在上面合适的地方加上吧,
这应该很简单吧,呵呵