📄 90586.htm
字号:
<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中的INI文件编程 </font><br><span class="nava"><font color="#CC9933">2000-07-04· -·-</font></span></p><fontcolor="#000000">INI文件在系统配置及应用程序参数保存与设置方面,具有很重要的作用,所以可视化的编程一族,如VB、VC、VFP、Delphi等都提供了读写INI文件的方法,其中Delphi中操作INI文件,最为简洁,这是因为Delphi3提供了一个TInifile类,使我们可以非常灵活的处理INI文件。</font><h3><fontcolor="#000000">一、有必要了解INI文件的结构:</font></h3><pre><fontcolor="#000000">;注释[小节名]关键字=值...</font></pre><fontcolor="#000000">INI文件允许有多个小节,每个小节又允许有多个关键字,“=”后面是该关键字的值。</font><p><fontcolor="#000000">值的类型有三种:字符串、整型数值和布尔值。其中字符串存贮在INI文件中时没有引号,布尔真值用1表示,布尔假值用0表示。</font><p><fontcolor="#000000">注释以分号“;”开头。</font><h3><fontcolor="#000000">二、定义</font></h3><fontcolor="#000000">1、在Interface的Uses节增加IniFiles;</font><p><fontcolor="#000000">2、在Var变量定义部分增加一行:</font><pre><fontcolor="#000000">myinifile:Tinifile;</font></pre><fontcolor="#000000">然后,就可以对变量myinifile进行创建、打开、读取、写入等操作了。</font><h3><fontcolor="#000000">三、打开INI文件</font></h3><pre><fontcolor="#000000">myinifile:=Tinifile.create('program.ini');</font></pre><fontcolor="#000000">上面这一行语句将会为变量myinifile与具体的文件program.ini建立联系,然后,就可以通过变量myinifile,来读写program.ini文件中的关键字的值了。</font><p><fontcolor="#000000">值得注意的是,如果括号中的文件名没有指明路径的话,那么这个Program.ini文件会存储在Windows目录中,把Program.ini文件存储在应用程序当前目录中的方法是:为其指定完整的路径及文件名。下面的两条语句可以完成这个功能:</font><pre><fontcolor="#000000">Filename:=ExtractFilePath(Paramstr(0))+'program.ini';myinifile:=Tinifile.Create(filename);</font></pre><h3><fontcolor="#000000">四、读取关键字的值</font></h3><fontcolor="#000000">针对INI文件支持的字符串、整型数值、布尔值三种数据类型,TINIfiles类提供了三种不同的对象方法来读取INI文件中关键字的值。</font><p><fontcolor="#000000">假设已定义变量vs、vi、vb分别为string、integer、boolean类型。</font><pre><fontcolor="#000000">vs:=myinifile.Readstring('小节名','关键字',缺省值);vi:=myinifile.Readinteger('小节名','关键字',缺省值);vb:=myinifile.Readbool('小节名','关键字',缺省值);</font></pre><fontcolor="#000000">其中缺省值为该INI文件不存在该关键字时返回的缺省值。</font><h3><fontcolor="#000000">五、写入INI文件</font></h3><fontcolor="#000000">同样的,TInifile类也提供了三种不同的对象方法,向INI文件写入字符串、整型数及布尔类型的关键字。</font><pre><fontcolor="#000000">myinifile.writestring('小节名','关键字',变量或字符串值);myinifile.writeinteger('小节名','关键字',变量或整型数值);myinifile.writebool('小节名','关键字',变量或True或False);</font></pre><fontcolor="#000000">当这个INI文件不存在时,上面的语句还会自动创建该INI文件。</font><h3><fontcolor="#000000">六、删除关键字</font></h3><fontcolor="#000000">除了可用写入方法增加一个关键字,Tinifile类还提供了一个删除关键字的对象方法:</font><pre><fontcolor="#000000">myinifile.DeleteKey('小节名','关键字');</font></pre><h3><fontcolor="#000000">七、小节操作</font></h3><fontcolor="#000000">增加一个小节可用写入的方法来完成,删除一个小节可用下面的对象方法:</font><pre><fontcolor="#000000">myinifile.EraseSection('小节名');</font></pre><fontcolor="#000000">另外Tinifile类还提供了三种对象方法来对小节进行操作:</font><p><fontcolor="#000000">myinifile.readsection('小节名',TStrings变量);可将指定小节中的所有关键字名读取至一个字符串列表变量中;</font><p><fontcolor="#000000">myinifile.readsections(TStrings变量);可将INI文件中所有小节名读取至一个字符串列表变量中去。</font><p><fontcolor="#000000">myinifile.readsectionvalues('小节名',TStrings变量);可将INI文件中指定小节的所有行(包括关键字、=、值)读取至一个字符串列表变量中去。</font><h3><fontcolor="#000000">八、释放</font></h3><pre><fontcolor="#000000">在适当的位置用下面的语句释放myinifile:myinifile.distory;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -