unit MyEdit;interfaceuses
SysUtils, Classes, Controls, StdCtrls;type
TMyEdit = class(TEdit)
private
{ Private declarations }
protected
procedure KeyPress(var Key: Char); override;
procedure DoExit;override;
procedure Change;override;
{ Protected declarations }
public
{ Public declarations }
published
constructor Create(AOwner:TComponent); override;
{ Published declarations }
end;procedure Register;implementationconstructor TMyEdit.Create(AOwner:TComponent);
begin
inherited Create(AOwner);
end;procedure TMyEdit.Change();
begin
//我想放在这里面来判断,判断用户不能输入,
// 意思就是 判断月份不能大于12end;procedure TMyEdit.KeyPress( var Key:Char);
begin
if not(key in['0'..'9',#8,#13]) then //若输入的不是数字键、删除键或回车键
begin
Key:=#0;
end;
inherited KeyPress( Key);
end;procedure TMyEdit.DoExit;
begin
if (Length(Text)=6) or (Length(Text)=4) then
begin
if Length(Text) = 6 then
begin
if StrToInt(Copy(Text,5,2))>12 then
begin
Text := '';
SetFocus;
Exit;
end;
end;
if Length(Text)= 4 then
begin
if StrToInt(Copy(Text,3,2)) > 12 then
begin
Text := '';
SetFocus;
Exit;
end
else
begin
if StrToInt(Copy(Text,1,2)) >30 then
Text := '19'+Text
else
Text := '20'+Text;
end;
end;
end
else
begin
SetFocus;
end;
inherited DoExit;
end;procedure Register;
begin
RegisterComponents('Standard', [TMyEdit]);
end;end.
解决方案 »
- 一段C语言,帮忙转成delphi的.谢谢.有多少分我送多少分.
- CXGRID 编辑列名,保存当前状态
- SDK 创建窗口失败的基础问题
- 使用ImgScan控件控制扫描仪报“扫描仪或扫描仪处理程序错误”!!!
- 我以前提的问题怎么找啊?
- 本热帝国理工,现在有一个pascal问题想请教大家~
- 用DBGrid直接連TTable一個字段[decimal(18,4)],輸入125.2000卻變成125.1999,為什麼會這樣?
- 小弟我都要不行呢.找了一个月,都没有找到,如何解决(在image上画圆时边缘出现锯齿现象,如何把边缘变的圆滑.)
- 当前日期减去8小时,怎样才能得到正确的日期??
- 我用MainQuery和TQuery做的一样的功能的模块,可是为什么实现的情况不同呢,初学者
- 买书散分
- 怎么实现在菜单中加入编辑框
var
Date: TDateTime;
begin
if TryStrToDate(DateStr, Date) then
ShowMessage('合法');
else
ShowMessage('不合法日期');
end;
是啊,直接用datetimepicker多省事啊