Stringgrid 数据判别问题!急!!

iloveva 2002-06-05 04:34:28
我在Stringgrid的cell中输入一些数据(float型)读入数组中,请问如何判断这些数据是数字而非其他的字母符号等,并给出提示(不是系统报错)
谢谢大家!!!
...全文
40 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
kplchx 2002-06-05
  • 打赏
  • 举报
回复
首先判断列,再检测键盘输入 onkeypress

if (not (key in ['0'..'9', #46, #8, #13])) then
key := #0;
if ((key in [#46]) and (pos('.', stringgrid1.Cells[stringgrid1.col, stringgrid1.row]) > 0)) then
key := #0;

在 onselectcell事件 或者你要进行数据处理的过程中 修正如‘.12’,‘12.’等问题
yourcol 是你要限制输入的列

for I := 1 to stringgrid1.RowCount - 1 do
begin
if pos('.', stringgrid1.cells[yourcol, i]) = 1 then
stringgrid1.Cells[yourcol, i] := '0' + stringgrid1.Cells[yourcol, i];
if pos('.', stringgrid1.cells[yourcol, i]) = length(stringgrid1.cells[yourcol, i]) then
stringgrid1.Cells[yourcol, i] := '0' + stringgrid1.Cells[yourcol, i] + '0';
东部一绝 2002-06-05
  • 打赏
  • 举报
回复
哦,对了还要判断当前是否是你要判断的列。
东部一绝 2002-06-05
  • 打赏
  • 举报
回复
还是帮你写写好
try
strtofloat(stringgrid1.cells[stringgrid1.col,stringgrid1.row]);
except
showmessage('输入不是数值');
//或则用application.messagebox('输入不是数值','提示',MB_OK+MB_ICONERROR);
CanSelect:=false;
end;
东部一绝 2002-06-05
  • 打赏
  • 举报
回复
在onSelectCell事件中判断
ACol:当前列
ARow:当前行
CanSelect:是否定位到当前的cell
刚离开的cell值为
stringgrid1.cells[stringgrid1.col,stringgrid1.row];//判断这值
可以用
try
strtofloat(stringgrid1.cells[stringgrid1.col,stringgrid1.row]);
except

end;

lanbada 2002-06-05
  • 打赏
  • 举报
回复
只有自己写个函数TRY了
windindance 2002-06-05
  • 打赏
  • 举报
回复
try
StrToFloat(StringGrid.Cell[i][j]);
except
ShowMessage('...');
end;

5,939

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧