我想可以在输入时检查一下,这是在OnKeyPress事件里的代码:
procedure TForm1.DBEdit1KeyPress(Sender: TObject; var Key: Char);
begin
try
if (StrToInt(DBEditDay.Text + Key) > 255) or (StrToInt(DBEditDay.Text + Key) < -254)then
Key := #0;
except
end;
end;
procedure TForm1.DBEdit1KeyPress(Sender: TObject; var Key: Char);
begin
try
if (StrToInt(DBEditDay.Text + Key) > 255) or (StrToInt(DBEditDay.Text + Key) < -254)then
Key := #0;
except
end;
end;
解决方案 »
- 求救:ssl加密
- 用过Tdbgrideh之类的控件的帮忙啊~~~~~
- Project manager里 Files怎么设置按字母排序?急
- 我想执行一段SQL SCRIPT(附脚本代码),请问应该用哪一个控件去执行,用ADOQUERY好像不太这代脚本太长了,还有什么办法吗
- convert问题,在线等待!!!
- 如何访问网络上的共享文件?
- 请问什么是三层构架?
- 帮帮我,这是怎么回事?在线等待
- 写一个使用三个表的select 语句
- 消息处理问题
- 请教!!如何让DirectoryListBox兼有DirectoryListBox和FileListBox的功能。
- 请问:哪里有在dbgrid中输入数据的例子。能进行数据有效性判断/
if (StrToInt(DBEditDay.Text + Key) > 32767) or (StrToInt(DBEditDay.Text + Key) < -32768) then
DELPHI的帮助。
//所以我在DBGrid1.KeyDown中打主意。请看:
function TForm1.GetDBGridEditingText(ADBGrid: TDBGrid): string;
var
i: integer;
begin
Result := '';
for i := 0 to ADBGrid.ControlCount - 1 do
if (ADBGrid.Controls[i] is TCustomEdit) and (TCustomEdit(ADBGrid.Controls[i]).Focused) then
Result := TCustomEdit(ADBGrid.Controls[i]).Text;
end;//判断它输入后,是否大于33000,小于33000,
//而不是在beforePost,afterpost...
procedure TForm1.DBGrid1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
var Value:string;
begin
case dbgrid1.selectedindex of
0://field1(smallint)
begin
Value:=GetDBGridEditingText(DBGrid1);
if Value<>'' then
if ((strtoint(Value)>=33000) or
(strtoint(Value)<=-33000)) then
begin
Showmessage('不能输入大于33000,小于33000的数');
Abort;//
end;
end;
end;
end;
话,就要自己负责更新数据,可看Tfield源码,他跳过默认操作了。
procedure TField.SetEditText(const Value: string);
begin
if Assigned(FOnSetText) then FOnSetText(Self, Value) else SetText(Value);
^^^^^^^^^^^^^^^^^^^ ^^^^^默认的操作
end;
根据tina的要求,field1>32675,<-32675,
在DBGrid中你只要打了回车,OnSetEditText事件没触发,倒是先抛出异常Eng
所以我觉得还是在onkeydown中处理好点。
如果在ONKEYDOWN处理,用户用鼠标也粘贴数据的话就无能为力了。
当然应该在ONSETTEXT里处理,不知你说的ONSETEDITTEXT事件是那个控件的?