try
StrToDate('2002-05-41');
Result := True;
except
Result := False;
end;
StrToDate('2002-05-41');
Result := True;
except
Result := False;
end;
解决方案 »
- 如何得到SQLSERVER中的所有数据库,及数据库中的表呀???
- 请问 dbgridEH 如何在 列头中加入背景 图 ????? 急!!!!!!! 我想 dbgridEH 在 某一列头中加入背景 图 ,但不能把列头
- 网络流量
- 又再遇到一个问题?
- 如何右键取得当前记录
- vb中有一个函数asc,delphi中有类似的函数吗?
- 关于随机函数的问题??急!
- 在应用程序服务器端编写的类,怎么在客户端应用程序创建该类的对象?
- www.DELPHIBBS.com上至今没有答案的问题???
- 急!超时问题。
- 菜鸟级问题,急~(在线)
- 同志们,帮帮忙啊!sql server+delphi,记录超过50000条,怎么提高读取速度?
try
StrToDate('2002-05-41');
Result := True;
except
Result := False;
end;
//大家怎么不用?
类似的还有:
function TryStrToDateTime(const S: string; out Value: TDateTime): Boolean;
function TryStrToInt(const S: string; out Value: Integer): Boolean;
function TryStrToInt64(const S: string; out Value: Int64): Boolean;
function StrToFloat(const S: string): Extended;
function StrToBool(const S: string): Boolean;
等等。
用不了
ThisDate: TDateTime;
begin
if TryStrToDate('2001-12-31', ThisDate) then
ShowMessage('正确的日期格式:' + DateToStr(thisdate)); if TryStrToDate('2001-12-32', ThisDate) then
ShowMessage('错误的日期格式');
end;
var
ThisDate: TDateTime;
begin
if TryStrToDate('2001-12-31', ThisDate) then
ShowMessage('正确的日期格式:' + DateToStr(thisdate)); if not TryStrToDate('2001-12-32', ThisDate) then
ShowMessage('错误的日期格式');
end;
trystrtodate(“可靠棵',thisdate)
好象不行 了
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;type
TForm1 = class(TForm)
Label1: TLabel;
Label2: TLabel;
Edit1: TEdit;
Edit2: TEdit;
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.DFM}//乘方函数,输入底数和幂,返回整型值
Function ChF(Di:Integer;Mi:Integer):integer;
var
i:Integer;
RS:Integer; begin
RS:=1;
for I:=1 to Mi do
RS:=RS*Di;
result:=RS;
end;
//出生日期校验函数
Function CheckDate(S:String):String;
var
YearTmp:Integer;
Montmp:Integer;
StrTmp:string;
DateTmp:Integer;
begin
YearTmp:=(Integer(s[7])-48)*1000+(Integer(s[8])-48)*100+
(Integer(s[9])-48)*10+(Integer(s[10])-48);
MonTmp:=(Integer(s[11])-48)*10+(Integer(s[12])-48);
DateTmp:=(Integer(s[13])-48)*10+(Integer(s[14])-48);
if (MonTmp=1)or(MonTmp=3)or(MonTmp=5)or(MonTmp=7)or(MonTmp=8)or(MonTmp=
10)or(MonTmp=12)then
begin
if (DateTmp>31)or(DateTmp=0) then
StrTmp:='no'
else
StrTmp:='yes';
end else if(MonTmp=4)or(MonTmp=6)or(MonTmp=9)or(MonTmp=11)then
begin
if(DateTmp>30)or(DateTmp=0)then
StrTmp:='no'
else
StrTmp:='yes';
end else if(MonTmp>12)or(MonTmp=0)then
StrTmp:='no'
else if MonTmp=2 then
begin
if(yearTmp mod 4<>0)and(MonTmp=2)and(DateTmp>28)then
StrTmp:='no'
else if (YearTmp mod 4=0)and(MonTmp=2)and(DateTmp>29)then
StrTmp:='no'
else
StrTmp:='yes';
end
else
StrTmp:='no'; result:=StrTmp;end;procedure TForm1.Button1Click(Sender: TObject);
var
I:integer;
StrGet:String;
Strtmp:String;
IntTmp:integer;
LastStr:String;begin
StrGet:=edit1.Text;
StrTmp:='';
IntTmp:=0;
//判断输入是否为空
if StrGet='' then
begin
MessageDlg('搞什么嘛!没有输入身份证号码~!', mtError,
[mbOk], 0);
exit;
end
//进行位数判断
else if (Length(StrGet)<>15)and(length(StrGet)<>17)and
(length(StrGet)<>18) then
begin
MessageDlg('我靠!位数不对,应该是15、17或者18位~!',
mtError,[mbOk], 0);
exit;
end
//如果输入为15位,加入“19”
else if length(StrGet)=15 then
begin
for i:=1 to 6 do
StrTmp:=StrTmp+StrGet[i];
StrTmp:=StrTmp+'19';
for I:=7 to Length(StrGet) do
StrTmp:=StrTmp+StrGet[i];
end
//如果输入为17位
else if length(StrGet)=17 then
StrTmp:=StrGet
//如果输入为18位
else if Length(StrGet)=18 then
begin
for i:=1 to 17 do
StrTmp:=StrTmp+StrGet[i];
end; for I:=17 downto 1 do
begin
//判断输入是否含有非数字字符
if(Integer(StrTmp[i])<48)or (Integer(Strtmp[i])>57) then
begin
messagedlg('老大!到底你会不会敲键盘啊!录入有非数字字符~!',mtError,[mbOk],0);
StrTmp:='';
exit;
end
end;
//校验日期
if CheckDate(StrTmp)='no' then
begin
messagedlg('黑老子,哪里有这种出生日期呀~!',mtError,[mbOk],0);
StrTmp:='';
exit;
end
else
begin
for i:=17 downto 1 do
begin
IntTmp:=IntTmp+(ChF(2,i)mod 11)*(integer(StrTmp[18-i])-48);
end;
IntTmp:=IntTmp mod 11;
case IntTmp of
0:LastStr:='1';
1:LastStr:='0';
2:LastStr:='X';
3:LastStr:='9';
4:LastStr:='8';
5:LastStr:='7';
6:LastStr:='6';
7:LastStr:='5';
8:LastStr:='4';
9:LastStr:='3';
10:LastStr:='2';
end;
end;
if StrTmp='' then
edit2.Text:=''
else
Edit2.Text:=StrTmp+LastStr;
end;procedure TForm1.Button2Click(Sender: TObject);
begin
Close;
end;end.