帮助文件里面有一个isdatetime函数,但好象不适用
解决方案 »
- 请问如何把字符串从aaabbb变成aaaCCCbbb,及在串某一个位置插入一串形成新串??
- 原生ADO??(再线)急!!!
- 请问delpfi各组件的属性与C++builder相同的组件有属是不是相同??
- 谁做过工资管理系统! 给点经验!
- 高频率刷新image时,图像抖动的解决方案?
- treeview 的data值的获取和比较问题
- delphi 中的图片上传怎么做?
- 我加了一个TEDIT和TButton,现在要求按了TButton后光标自动回到TEdit,最好能选中TEdit中的内容,请问怎么做?
- 一个关于windows消息的问题
- 50分献上,我的问题可能有点难:我要顺序执行两个exe文件(即第一个exe退出后再调用第二个exe),假如第一个exe的执行被取消,则不执行第二个exe。请问用Delphi如何实现?
- 大量的插入语句,怎么做比较有效率。我测试了,还是迷茫ing...
- 如果操作带有密码的paradox表?
try
StrToDateTime(edit1.text);
except
Showmessage('不是日期');
..其它处理..
end;
可以写在edit的onExit事件或其它地方
if TryStrToDateTime(edit1.text, nDate) then
showmessage("是日期");uses
dateUtils;
function CheckDateTimeValid(aString: string): boolean;
begin
aString := Copy(aString,1,16);
if aString = '' then
begin
result := true;
exit;
end;
if (trim(aString) = '/ / :') or
(trim(aString) = '- - :') then
begin
result := true;
exit;
end;
if (Length(aString) <> 16) or
((Pos(' ',aString) <> 0) and (Pos(' ',aString) <> 11)) then
begin
Result := false;
InformationMessageBox('无效');
exit;
end;
try
strtodatetime(aString);
result := true;
except
InformationMessageBox('无效');
result := false;
end;
end;
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DateUtils, StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
var
nDate: TDateTime;
begin
if TryStrToDateTime(Edit1.Text, nDate) then
ShowMessage('IS DateTime');
end;end.
uses
dateUtils;
CSDN小助手是一款脱离浏览器也可以访问Csdn论坛的软件
界面:http://blog.csdn.net/Qqwwee_Com/archive/2005/10/16/504620.aspx
下载:http://szlawbook.com/csdnv2/csdnv2.rar为神六喝彩,向所有科技工作者致敬!
拒绝日货。
procedure TForm2.RzEdit10KeyPress(Sender: TObject; var Key: Char);
begin
if (not (key in ['0'..'9',#8])) and (key <>':') and (key<>'-') and (key<>' ')then key:=#0;
end;procedure TForm2.RzEdit10Enter(Sender: TObject);
begin
if RzBitBtn4.Tag=0 then MessageBox(Handle,'ÒªÔö¼ÓÐÅÏ¢ÇëÏȲéѯºóÔÙµã»÷Ôö¼Ó°´Å¥Ôö¼ÓÐÅÏ¢','ÌáʾÐÅÏ¢',MB_OK+MB_ICONINFORMATION)
else TRzEdit(Sender).Text:=FormatDateTime('yyyy-mm-dd hh:mm:ss',Now);
end;procedure TForm2.RzEdit10Exit(Sender: TObject);
var
i,temnum:Integer;
str,substr:string;
begin
if RzBitBtn4.Tag<>0 then
begin
str:=RzEdit10.Text;
if length(str)=19 then
begin
for i:=1 to length(str) do
begin
case i of
1..4,6..7,9..10,12..13,15..16,18..19:
if (str[i]<'0') or (str[i]>'9') then
begin
MessageBox(Handle,'ÄúÊäÈëµÄÈÕÆÚʱ¼ä¸ñʽ²»ÕýÈ·,ÇëÖØÐÂÊäÈë(ÀýÈç:2005-10-10 10:10:10)','ÌáʾÐÅÏ¢',MB_OK+MB_ICONINFORMATION);
RzEdit10.SetFocus;RzEdit10.SelectAll;
Exit;
end;
5,8:
if str[i]<>'-' then
begin
MessageBox(Handle,'ÄúÊäÈëµÄÈÕÆÚʱ¼ä¸ñʽ²»ÕýÈ·,ÇëÖØÐÂÊäÈë(ÀýÈç:2005-10-10 10:10:10)','ÌáʾÐÅÏ¢',MB_OK+MB_ICONINFORMATION);
RzEdit10.SetFocus;RzEdit10.SelectAll;
Exit;
end;
11:
if str[i]<>' ' then
begin
MessageBox(Handle,'ÄúÊäÈëµÄÈÕÆÚʱ¼ä¸ñʽ²»ÕýÈ·,ÇëÖØÐÂÊäÈë(ÀýÈç:2005-10-10 10:10:10)','ÌáʾÐÅÏ¢',MB_OK+MB_ICONINFORMATION);
RzEdit10.SetFocus;RzEdit10.SelectAll;
Exit;
end;
14,17:
if str[i]<>':' then
begin
MessageBox(Handle,'ÄúÊäÈëµÄÈÕÆÚʱ¼ä¸ñʽ²»ÕýÈ·,ÇëÖØÐÂÊäÈë(ÀýÈç:2005-10-10 10:10:10)','ÌáʾÐÅÏ¢',MB_OK+MB_ICONINFORMATION);
RzEdit10.SetFocus;RzEdit10.SelectAll;
Exit;
end;
end;
end; substr:=Copy(str,6,2);
temnum:=StrToInt(substr);
if (temnum<1) or (temnum>12) then
begin
MessageBox(Handle,'ÄúÊäÈëµÄÔ·ݸñʽ²»ÕýÈ·,ÇëÖØÐÂÊäÈë(ÀýÈçÔ·ݷ¶Î§:01-12)','ÌáʾÐÅÏ¢',MB_OK+MB_ICONINFORMATION);
RzEdit10.SetFocus;RzEdit10.SelectAll;
Exit;
end; substr:=Copy(str,9,2);
temnum:=StrToInt(substr);
if (temnum<1) or (temnum>31) then
begin
MessageBox(Handle,'ÄúÊäÈëµÄÈÕ¸ñʽ²»ÕýÈ·,ÇëÖØÐÂÊäÈë(ÀýÈçÈÕ·¶Î§:01-31)','ÌáʾÐÅÏ¢',MB_OK+MB_ICONINFORMATION);
RzEdit10.SetFocus;RzEdit10.SelectAll;
Exit;
end; substr:=Copy(str,12,2);
temnum:=StrToInt(substr);
if temnum>23 then
begin
MessageBox(Handle,'ÄúÊäÈëµÄСʱ¸ñʽ²»ÕýÈ·,ÇëÖØÐÂÊäÈë(ÀýÈçСʱ·¶Î§:00-23)','ÌáʾÐÅÏ¢',MB_OK+MB_ICONINFORMATION);
RzEdit10.SetFocus;RzEdit10.SelectAll;
Exit;
end; substr:=Copy(str,15,2);
temnum:=StrToInt(substr);
if temnum>59 then
begin
MessageBox(Handle,'ÄúÊäÈëµÄ·ÖÖÓ¸ñʽ²»ÕýÈ·,ÇëÖØÐÂÊäÈë(ÀýÈç·ÖÖÓ·¶Î§:00-59)','ÌáʾÐÅÏ¢',MB_OK+MB_ICONINFORMATION);
RzEdit10.SetFocus;RzEdit10.SelectAll;
Exit;
end; substr:=Copy(str,18,2);
temnum:=StrToInt(substr);
if temnum>59 then
begin
MessageBox(Handle,'ÄúÊäÈëµÄÃë¸ñʽ²»ÕýÈ·,ÇëÖØÐÂÊäÈë(ÀýÈçÃ뷶Χ:00-59)','ÌáʾÐÅÏ¢',MB_OK+MB_ICONINFORMATION);
RzEdit10.SetFocus;RzEdit10.SelectAll;
Exit;
end;
end else
begin
MessageBox(Handle,'ÇëÊäÈëÍêÕûµÄÈÕÆÚʱ¼äÐÅÏ¢','ÌáʾÐÅÏ¢',MB_OK+MB_ICONINFORMATION);
RzEdit10.SetFocus;RzEdit10.SelectAll;
Exit;
end;
end;
这是我在开发软件一部分代码:大致给你说下思路:
1、KEYPRESS事件,可以输入的值
2、ENTER 取系统事件,也可以修改
3、EXIT 判断