新!日期处理控件。

lxj_com2006 2007-01-11 09:55:37

新!日期处理控件。

不使用任何其它日期控件,直接在 TEdit 中实现,

只能输入日期格式 如: 2007-1-10

月份不能大于12,天最好能控制不能超过月的最大天。

如何实现,有没有代码???
...全文
250 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
仙侣步惊云 2007-01-12
  • 打赏
  • 举报
回复
应该是很容易的,首先是限定为数据输入,再用delphi的函数判断是否是有效的日期
nevergetwin 2007-01-12
  • 打赏
  • 举报
回复
为什么不用MaskEdit?
aniugee 2007-01-12
  • 打赏
  • 举报
回复
用TEDITMASK控件,更改其中一个属性EditMask,在里面选择你要的格式就行了
有个小缺点是,在输入时会有一条细线在控制你的输入
flashtong 2007-01-11
  • 打赏
  • 举报
回复

function isdate(str: string): Boolean;
const datastr = '1234567890-';
var i: integer;
datestrlist: tstringlist;
begin
Result := False;
if length(trim(str)) < 1 then exit;
for i := 1 to length(str) do
if (pos(str[i], datastr) < 1) then exit;
datestrlist := tstringlist.Create;
datestrlist := split(str, '-');
try
with datestrlist do
begin
if Count <> 3 then exit;
if not isInteger(Strings[0]) then exit;
if not isInteger(Strings[1]) then exit;
if not isInteger(Strings[2]) then exit;
if (strtoint(Strings[0]) < 1500) or (strtoint(Strings[0]) > 5000) then exit;
if (strtoint(Strings[1]) < 1) or (strtoint(Strings[1]) > 12) then exit;
if (strtoint(Strings[2]) < 1) or (strtoint(Strings[2]) > 31) then exit;
end;
Result := true;
finally
datestrlist.Free;
end;
end;

//这个函数基本能够实现,但是不能检查2-31这样的错误,你如果需要就加上吧,我用是够了。
yousite1 2007-01-11
  • 打赏
  • 举报
回复
用KEYPRESS事件去处理可以实现的。不过太麻烦了。
zhengsq007 2007-01-11
  • 打赏
  • 举报
回复
能实现,可是没必要
pongjun64 2007-01-11
  • 打赏
  • 举报
回复
方法是人想出来的,这个只能自己去解决了
lxj_com2006 2007-01-11
  • 打赏
  • 举报
回复

肯定有的。
hongqi162 2007-01-11
  • 打赏
  • 举报
回复
实现起来相当麻烦,没有代码



回帖完毕
qzmp_sc 2007-01-11
  • 打赏
  • 举报
回复
汗。。。日期还有28,29,30,31天的咧~~比较罗嗦
lxj_com2006 2007-01-11
  • 打赏
  • 举报
回复

我是想要能过滤的那种,非法日期不能输入!
lxj_com2006 2007-01-11
  • 打赏
  • 举报
回复

能不能做一个在输入时就控制的
flashtong 2007-01-11
  • 打赏
  • 举报
回复

楼上的功能是实现了
但是用异常的不好
aniugee 2007-01-11
  • 打赏
  • 举报
回复
procedure TfrmCHECKE.Edit1Exit(Sender: TObject);
begin
inherited;
if trim(Edit1.Text)='' then exit;
if not GF_Is_Date(Edit1.Text) then
begin
uf_Alert(''''+Edit1.Text+'''是无效的日期值!');
Edit1.Text:='';
Edit1.SetFocus;
end;
end;

function GF_Is_Date(StrDate: String): Boolean;
var
s_Date: String;
begin
s_Date:= Trim(StrDate);
begin
try
StrToDate(s_Date);
result:= true;
except
result:= false;
end;
end;
end;
试试这个!

5,388

社区成员

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

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