⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 115116.htm

📁 在天极网上发布的各类delphi原码及技巧文档
💻 HTM
📖 第 1 页 / 共 2 页
字号:
<html xmlns="http://www.w3.org/TR/xhtml1/strict">   <head>      <title>天极网</title>      <meta http-equiv="Content-Type" content="text/html; charset=gb2312"></meta>      <meta http-equiv="Pragma" content="no-cache"></meta>      <meta http-equiv="expires" content="Mon,12 May 1998 00:36:05 GMT"></meta>      <link rel="stylesheet" href="/xslimages/css/cpcw.css"></link>   </head>   <style>.nava {  font-size: 9pt}.font1{font-size: 10.5pt}</style>   <body bgcolor="#FFFFFF" topmargin="2"><table width="760" border="0" cellspacing="0" cellpadding="0" align="center"><tr><td width="20%" rowspan="3" valign="top" align="center"><table width="95%" border="1" cellspacing="0" cellpadding="0" height="60" bordercolorlight="#CCCCCC" bordercolordark="#FFFFFF"><tr valign="middle" align="center"><td><div align="center"><span class="nava">天极硬件,新闻及时<br>资料详尽,敬请关注<br><a href="/33554432/35651584/yingjian.htm">www.myhard.com</a></span></div></td></tr></table></td><td width="57%" valign="bottom" rowspan="3" align="center"><div align="center"><script language="JavaScript" src="http://ad.cpcw.com/js/school.js"></script></div></td><td width="20%" valign="top" rowspan="3" align="center"><table width="95%" border="1" cellspacing="0" cellpadding="0" height="60" bordercolorlight="#CCCCCC" bordercolordark="#FFFFFF"><tr valign="middle" align="center"><td><div align="center"><span class="nava">好又多电子商务<br>让您一点动心<br><a href="http://www.hoyodo.com">www.hoyodo.com</a></span></div></td></tr></table></td></tr><tr></tr><tr></tr></table><table width="760" border="0" cellspacing="0" cellpadding="0" height="70" align="center"><tr><td width="145" valign="bottom" rowspan="3"><img src="/xslimages/content/logo.gif" width="140" height="60"></img></td><td colspan="3" width="100%" height="33" align="center"><a href="/" target="_blank">首页</a>|    <a href="/33554432/36700160/news.htm" target="_blank">新闻中心</a>|     <a href="/33554432/50331648/business.htm" target="_blank">企业中心</a>|	 <a href="/33554432/41943040/caijing.htm" target="_blank">财经中心</a>|  	 <a href="/33554432/39845888/fashion.htm" target="_blank">时尚中心</a>| 	 <a href="/33554432/35651584/yingjian.htm" target="_blank">硬件中心</a>| 	 <a href="/33554432/34603008/school.htm" target="_blank">学习中心</a>| 	 <a href="/33554432/37748736/game.htm" target="_blank">游戏中心</a>| 	 <a href="/33554432/38797312/ziyuan.htm" target="_blank">资源中心</a>| 		 <a href="http://www.hoyodo.com/" target="_blank">社区</a>| 	 <a href="http://training.yesky.com/" target="_blank">网校</a></td></tr><tr><td colspan="3" width="78%" height="20" align="right"><b>中心栏目:<a href="http://www.mydown.com" target="_blank"><font color="#FF0000"><u>红辣椒软件下载</u></font></a></b><a href="http://soft.yesky.com" target="_blank">       软件之窗 </a><a href="http://desktop.yesky.com" target="_blank">天极桌面网 </a><a href="http://art.yesky.com" target="_blank">美工教室       </a><a href="http://itdreamer.yesky.com" target="_blank">程序方舟 </a><a href="http://homepage.yesky.com" target="_blank">网页陶吧       </a><a href="http://safe.yesky.com" target="_blank">安全之路</a><a href="http://soft.yesky.com" target="_blank"></a></td></tr></table><table align="center" border="0" cellpadding="0" cellspacing="0" width="760"><tbody><tr bgcolor="#333333"><td colspan="2" height="1"></td></tr><tr><td bgcolor="#ff9900" height="16" valign="bottom" width="72%"><font color="#000000"><b><font color="#ffffff">学 习 中 心</font></b></font></td><td bgcolor="#6699cc" height="16" width="28%"><div align="center"><font face="Arial, Helvetica, sans-serif"><b><font color="#ffffff">N         E T S C H O O L</font></b></font></div></td></tr><tr bgcolor="#333333"><td colspan="2" height="1"></td></tr></tbody></table><table align="center" border="0" cellpadding="0" cellspacing="0" width="760" bgcolor="#eeeeee"><td colspan="2" height="28"><div align="center"><a href="/33554432/34603008/34635776/34636800/34636832/schoolinverse1.htm" target="_blank"><font color="#000000">HTML</font></a><font color="#000000"> _</font><a href="/33554432/34603008/34635776/34636800/34636864/schoolinverse1.htm" target="_blank"><font color="#000000">JavaScript</font></a><font color="#000000"> _</font><a href="/33554432/34603008/34635776/34636800/34636928/schoolinverse1.htm" target="_blank"><font color="#000000">CSS</font></a><font color="#000000">               _              <a href="/33554432/34603008/34635776/34637824/34637952/schoolinverse1.htm" target="_blank"><font color="#000000">                  PHP                </font></a><font color="#000000">                 _              </font></font><a href="/33554432/34603008/34635776/34637824/34637888/schoolinverse1.htm" target="_blank"><font color="#000000">ASP</font></a><font color="#000000"> _</font><a href="http://www.yesky.com/33554432/34603008/34635776/34637824/34637920/schoolinverse1.htm" target="_blank"><font color="#000000">Perl</font></a><font color="#000000"> _</font><a href="/33554432/34603008/34635776/34638848/34638880/schoolinverse1.htm" target="_blank"><font color="#000000">Dreamweaver</font></a><font color="#000000"> _</font><a href="/33554432/34603008/34635776/34639872/34639904/schoolinverse1.htm" target="_blank"><font color="#000000">XML</font></a><font color="#000000"> _</font><a href="http://www.yesky.com/33554432/34603008/34734080/schoolinverse2.htm" target="_blank"><font color="#000000">病毒</font></a><font color="#000000"> _</font><a href="http://www.yesky.com/67108864/68157440/68419584/inverse2.htm" target="_blank"><font color="#000000">程序开发</font></a><font color="#000000"> _</font><a href="http://www.yesky.com/33554432/34603008/34799616/34800640/schoolinverse1.htm" target="_blank"><font color="#000000">Email</font></a><font color="#000000"> _</font><a href="http://www.yesky.com/33554432/34603008/34897920/34898944/schoolinverse1.htm" target="_blank"><font color="#000000">Windows 9x</font></a><font color="#000000"> _</font><a href="/33554432/34603008/34897920/34900992/schoolinverse1.htm" target="_blank"><font color="#000000">Linux</font></a><font color="#000000"> _</font><a href="/33554432/34603008/34963456/34966528/schoolinverse1.htm" target="_blank"><font color="#000000">WPS</font></a><font color="#000000"> _</font><a href="http://www.yesky.com/33554432/34603008/34963456/34964480/schoolinverse1.htm" target="_blank"><font color="#000000">Word</font></a></div></td></table><table width="760" border="0" cellspacing="0" cellpadding="0" height="30" align="center"><tr><td align="left" valign="bottom"><span class="nava"><span class="nava"><a href="/index.htm">首页</a>→              <a href="/33554432/34603008/school.htm">学习中心</a>→              <a href="/33554432/34603008/34668544/schoolinverse2-pro.htm">程序方舟</a>→              <a href="/33554432/34603008/34668544/34672640/schoolinverse2.htm">技巧经验</a>→              <a href="/33554432/34603008/34668544/34672640/34672672/schoolinverse1.htm">DELPHI技巧</a>→              </span></span></td><td width="2%"></td></tr></table><table width="760" border="0" cellspacing="0" cellpadding="0" align="center"><tr><td colspan="3" valign="top" width="75%"><table width="98%" border="0" cellspacing="1" cellpadding="1" bgcolor="#000000"><tr bgcolor="#FFFFFF"><td width="100%" colspan="4" align="left"><table width="95%" align="center"><tr><td class="font1"><p align="center"><br><font size="3">在Delphi中处理数据库日期型字段的显示与输入</font><br><span class="nava"><font color="#CC9933">2000-09-18·						  yh·delhpi技术网</font></span></p>  在使用Delphi进行数据库设计时,不可避免的会涉及到日期型字段的输入问题。不过与Microsoft的Access 97中文版等相比,Delphi本身提供的日期型字段的显示和输入方式并不适合中国人的习惯。因此对于日期型字段的处理,大家提出了不少解决方法,但是处理结果在显示和输入上并不统一,例如显示时可以实现“yyyy年mm月dd日”的格式,但是在输入时还是要按照国外的习惯用“yyyy-mm-dd”的形式进行输入;而使用TdateTimePicker进行选择输入总嫌麻烦;有些方法还要修改系统的一些设置属性,因而在进行软件发布时要将系统的属性进行调整;采用第三方控件的方式则还要将控件打包发布。而且对于常用到的“1999年”、“1999年11月”等日期格式,没有进行相应的处理。这里我根据自己的实践,利用TField的OnGetText和OnSetText两个事件的结合,以期达到日期型字段的显示和输入的统一,并可以处理我们常见的“1999年”、“1999年11月”等日期形式的显示和输入,全部利用Delphi提供的事件实现,不需要修改任何系统设置。进行相应的扩展后,还可以用于时间的显示和输入,如“hh点mm分”等。同时,由于是直接控制TField的事件,所以不论使用TDBGrid还是用TDBEdit,都可以正常的进行统一处理,而不必分开考虑。采用类似的方法,还可以应用于非数据库应用程序中的日期输入。 <br><br>1 基本思想 <br><br>  利用TField的EditMask属性,将其同时作为显示和输入的掩码,在TField的OnGetText事件中处理日期字段的显示,而在OnSetText事件中处理输入值的有效性判断。为了重复利用代码,将OnGetText和OnSetText的事件处理过程调用的过程和函数放到一个独立的单元中。 <br><br>2 具体实现代码 <br><br>{显示和判断单元}<br>unit DBDateEditMaskTrans;<br>interface<br>uses<br>&nbsp;&nbsp;Windows, SysUtils, Controls, Forms,Db;<br><br>&nbsp;&nbsp;{日期型字段显示过程,在OnGetText事件中调用}<br>&nbsp;&nbsp;procedure DateFieldGetText(Sender: TField; var Text: String);<br><br>&nbsp;&nbsp;{日期型字段输入判断函数,在OnSetText事件中调用}<br>&nbsp;&nbsp;function DateFieldSetText(Sender: TField; const Text: String):Boolean;<br><br>implementation<br><br>procedure DateFieldGetText(Sender: TField; var Text: String);<br>var<br>&nbsp;&nbsp;  dDate:TDate;<br>&nbsp;&nbsp;  wYear,wMonth,wDay:Word;<br>&nbsp;&nbsp;  aryTestYMD:Array [1..2] of Char ;{测试输入掩码用临时数组}<br>&nbsp;&nbsp;  iYMD:Integer;<br>begin<br>&nbsp;&nbsp;  dDate:=Sender.AsDateTime;<br>&nbsp;&nbsp;  DecodeDate(dDate,wYear,wMonth,wDay);<br>{测试输入掩码所包含的格式.}<br>&nbsp;&nbsp;  aryTestYMD:=’年’;<br>&nbsp;&nbsp;  if StrScan(PChar(Sender.EditMask),<br>  aryTestYMD[1])&#60; &#62;nil then<br>&nbsp;&nbsp;&nbsp;&nbsp;  iYMD:=1;<br>&nbsp;&nbsp;&nbsp;&nbsp;  aryTestYMD:=’月’;<br>&nbsp;&nbsp;  if StrScan(PChar(Sender.EditMask),<br>  aryTestYMD[1])&#60; &#62;nil then<br>&nbsp;&nbsp;&nbsp;&nbsp;  iYMD:=2;<br>&nbsp;&nbsp;&nbsp;&nbsp;  aryTestYMD:=’日’;<br>&nbsp;&nbsp;  if StrScan(PChar(Sender.EditMask),<br>  aryTestYMD[1])&#60; &#62;nil then<br>&nbsp;&nbsp;&nbsp;&nbsp;  iYMD:=3;<br><br>&nbsp;&nbsp;case iYMD of<br>&nbsp;&nbsp;&nbsp;&nbsp; 1:{输入掩码为:”yyyy年”的格式.}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  Text:=IntToStr(wYear)+’年’;<br>&nbsp;&nbsp;&nbsp;&nbsp; 2: {输入掩码为:”yyyy年mm月”的格式.}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  Text:=IntToStr(wYear)+’年’+IntToStr(wMonth)+’月’;<br>&nbsp;&nbsp;&nbsp;&nbsp; 3: {输入掩码为:”yyyy年mm月dd日”的格式.}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  Text:=IntToStr(wYear)+’年’+IntToStr(wMonth)+’月’ +IntToStr(wDay)+’日’;<br>&nbsp;&nbsp; else {默认为:”yyyy年mm月dd日”的格式.}<br>&nbsp;&nbsp;&nbsp;&nbsp;  Text:=IntToStr(wYear)+’年’+IntToStr(wMonth)+’月’ +IntToStr(wDay)+’日’;<br>&nbsp;&nbsp;end;<br><br>end;<br><br>function DateFieldSetText(Sender: TField; const Text: String):Boolean;<br>var<br>&nbsp;&nbsp;  dDate:TDate;<br>&nbsp;&nbsp;  sYear,sMonth,sDay:String;<br>&nbsp;&nbsp;  aryTestYMD:Array [1..2] of Char;<br>&nbsp;&nbsp;  iYMD:Integer;<br>begin<br>&nbsp;&nbsp;{获得用户输入的日期}<br>&nbsp;&nbsp;  sYear:=Copy(Text,1,4);<br>&nbsp;&nbsp;  sMonth:=Copy(Text,7,2);<br>&nbsp;&nbsp;  SDay:=Copy(Text,11,2);<br><br>&nbsp;&nbsp;{测试输入掩码所包含的格式.}<br>&nbsp;&nbsp;  aryTestYMD:=’年’;<br>&nbsp;&nbsp;if StrScan(PChar(Sender.EditMask),<br>  aryTestYMD[1])&#60; &#62;nil then<br>&nbsp;&nbsp;&nbsp;&nbsp;  iYMD:=1;<br>&nbsp;&nbsp;  aryTestYMD:=’月’;<br>&nbsp;&nbsp;if StrScan(PChar(Sender.EditMask),<br>  aryTestYMD[1])&#60; &#62;nil then<br>&nbsp;&nbsp;&nbsp;&nbsp;  iYMD:=2;<br>&nbsp;&nbsp;  aryTestYMD:=’日’;<br>&nbsp;&nbsp;if StrScan(PChar(Sender.EditMask),<br>  aryTestYMD[1])&#60; &#62;nil then<br>&nbsp;&nbsp;&nbsp;&nbsp;  iYMD:=3;<br><br>&nbsp;&nbsp;{利用Try…Except进行输入的日期转换}<br>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -