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

📄 78728.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-06-11·						  -·中国计算机世界出版服务公司</font></span></p><p>  Delphi3内建的Borland数据库 引擎(BDE),使Delphi3程序能通过数据库别名(DatabaseAlias)十分方便地访问各种类型的数据库。然而,数据库别名的建立、修改、删除等维护工作,需要在BDEAdministrator 中进行,数据库中实际表格结构的建立和维护,有时也要在DataBaseDesktop中完成,这给用户增加了不少困难。有没有办法让用户不去执行BDEAdministrator 和DataBaseDesktop这两个应用程序,就可直接检测、建立数据库别名和库中的表格呢?笔者通过探索,得到了一种可行的方案,现以笔者所开发 的一个单机版的图书资料管理系统为例,简要加以说明。</p> <p><strong>一、数据库别名(Alias)的定义和检测方法</strong><br>   当Type为STANDARD时,别名定义最 为简单,这时仅能采用PARADOX,DBASE,ASCIIDRV三种数据库作为缺省的驱动程序(DEFAULTDRIVER)。</p> <p>  另外,还要定义数据库存放路径(PATH) 和ENABLEBCD,才能建立一个完整的数据库别名。</p> <p>  Delphi的数据库应用程序能自 动提供一个Session组件,这个Session组件即为应用程序与BDE的接口。 </p> <p><b>1.检测别名</b><br>   通过调用Session.GetAliasNames(list:Tstrings) 方法,可将当前BDE配置中的所有数据库别名的名称存放到List字符串列表中。list.IndexOf('需要检测的别名')的值会告诉我们这个别名是否 存在(其值为1时不存在)。</p> <p><b>2.增加一个新的别名</b><br>   Session组件的过程AddStandardAlias(constName,Path,DefaultDriver:string),可以增加一个标准类型的数据库别名。例如增加一个名为Cntssamp,缺省数据库驱动程序为PARADOX、存 放路径为c:\delphp11的别名:</p> <blockquote>  <blockquote>  <p> Session.AddStandardAlias('Cntssamp','c:\delphp11','Paradox');  </p> </blockquote> </blockquote> <p><b>3.BDE配置文件存盘</b></p> <blockquote>  <blockquote>  <p> Session.SaveConfigFile;</p> </blockquote> </blockquote> <p><strong>二、数据库中表格的定义和检测方法<br> </strong>  数据库中表格的定义、 维护和使用,只有在数据库别名正确设置的情况下才有意义。以TTable组 件为例,必须设置其DatabaseName为一个实际存在的别名。</p> <p><b>1.检测表格是否存在</b><br>   通过调用Session.GetTableNames(constDatabaseName,Pattern:string;<br> Extensions,SystemTables:Boolean; List:TStrings)方法,可将当前指定数据库别名中所有表格的名称存放  到List字符串列表中。list.IndexOf('需要检测的表格名')的值会告诉 我们这个表格是否存在(其值为1时不存在)。</p> <p><b>2.建立一个表格</b><br>   第一步,设置TTable组件的DataBase Name(别名)、TableName(表格名)、TableType(数据库类型);<br>   第二步,调用Table.FieldDefs.Add(constName:string;DataType:FieldType;Size:Word;Required:Boolean)增加表格的各个字段,其中Name为字段名,DataType为字段类型(常用的有ftInteger,ftString,ftDate,ftBoolean等),Size为字段长度,Required为该字段是否允许有空值。<br>   第三步,调用Table.IndexDefs.Add(const Name,Fields:string;Options:TIndexOptions)方法增加表格的索引文件,其中Name为索引文件名,Fields为索引字段,options为索引参数 的集合,常用的索引参数有ixPrimary(主键)、ixDescending(降序)、ixUnique( 具有唯一值)等。<br> 第四步,调用Table.CreateTable 建立表格。</p> <p><strong>三、一个实例<br> </strong>  在Form1.Formcreate事 件中写入如下代码,程序启动时,将自动检测是否存在数据库别名Cntssamp,如果没有则建立之;自动检测别名Cntssamp中是否存在表格TSK(图书库), 如果没有则自动建立表格TSK。</p> <blockquote>  <blockquote> <p>procedureTForm1.FormCreate(Sender: TObject);<br> var<br> ap:TStringList;{字符串列表变量}<br> answer:Integer;<br> begin<br> ap:=TStringlist.Create;<br> Session.GetAliasNames(ap);{取得别名列表}<br> if(ap.IndexOf('Cntssamp')=1)then{判断别名是否存在}<br> begin<br> answer:=Application.MessageBox('别名Cntssamp不存在,现在创建吗?','BDE信息窗口',mb_OKCancel);<br> {增加一个名为Cngzsamp的数据库别名}<br> ifanswer=IDCANCELthen<br> begin<br> ap.Free;<br> Exit;<br> end;<br>

⌨️ 快捷键说明

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