请问在DBGrid表格的日期型字段中输入其它的字符会出错有方法避免吗?(50分)

给你个参考
procedure Twin_hbjl.Edit3KeyPress(Sender: TObject; var Key: Char);
begin
if not(key in ['0'..'9'])and not(key=Chr(vk_Back))and not(key=#13) then
begin
showmessage(' 请输入数字 ');
exit;
end;
if key=#13 then
button1.SetFocus;
end;
如果找不到日期型字段的触发时间话,那就不要直接在DBGrid中输入吧,用EDIT输入,麻烦点
 
1:您可以捕捉错误,然后加入自己的提示。
2:您也可以设置日期型字段的EditMask属性为Date,其他字符就输不进去。
 
建议用maskedit
 
1、建立固定字段,编辑该字段的editmask
2、在dataset的onerror事件中编写代码,
procedure TForm1.Query1EditError(DataSet: TDataSet; E: EDatabaseError;
var Action: TDataAction);
begin
action:=daAbort;
showmessage('输入错误');
end;
 
procedure Edit1KeyPress;
begin
try
inttodatetime(edit1.text);
except
showmessage('日期格式不对') ;
end;
end;
 
terry_lzs的办法才是最好的。我既是这样处理的。可以通过处理错误类来
处理错误信息。
 
用Datatimepicker安全些!
 
用这个函数检测一下输入的数据!
function isdate(s:string):boolean;
begin
result:=false;
try
strtodate(s);
result:=true;
except
on econverterror do
result:=false;
end;
end;
 
接受答案了.
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
D
回复
0
查看
901
DelphiTeacher的专栏
D
I
回复
0
查看
536
import
I
顶部