王米米 發表於 2008-3-15 18:14:36

delphi建立、读取、存贮INI文件的方法《三》

从.INI文件中获取字符串 <BR>  var <BR>  strResult:pchar; <BR>  begin <BR>  GetPrivateProfileString( <BR>  &acute;windows&acute;,&nbsp;//&nbsp;[]中标题的名字 <BR>  &acute;NullPort&acute;,&nbsp;//&nbsp;=号前的名字 <BR>  &acute;NIL&acute;,&nbsp;//&nbsp;如果没有找到字符串时,返回的默认值 <BR>  strResult,&nbsp;//存放取得字符 <BR>  100,&nbsp;//取得字符的允许最大长度 <BR>  &acute;c:\forwin95\win.ini&acute;&nbsp;//&nbsp;调用的文件名 <BR>  ); <BR>  edit1.text:=strResult;&nbsp;//显示取得字符串 <BR>  从.INI文件中获取整数 <BR>  edit1.text:=inttostr(GetPrivateProfileInt( <BR>  &acute;intl&acute;,&nbsp;//&nbsp;[]中标题的名字 <BR>  &acute;iCountry&acute;,&nbsp;//&nbsp;=号前的名字 <BR>  0,//&nbsp;如果没有找到整数时,返回的默认值 <BR>  &acute;c:\forwin95\win.ini&acute;&nbsp;//&nbsp;调用的文件名 <BR>  )); <BR>  向.INI文件写入字符串 <BR>  WritePrivateProfileString( <BR>  &acute;windows&acute;,&nbsp;//&nbsp;[]中标题的名字 <BR>  &acute;load&acute;,&nbsp;//&nbsp;要写入“=”号前的字符串 <BR>  &acute;accca&acute;,&nbsp;//要写入的数据 <BR>  &acute;c:\forwin95\win.ini&acute;&nbsp;//&nbsp;调用的文件名 <BR>  ); <BR>  向.INI文件写入整数 <BR>  WritePrivateProfileSection( <BR>  &acute;windows&acute;,&nbsp;//&nbsp;[]中标题的名字 <BR>  &acute;read=100&acute;,&nbsp;//&nbsp;要写入的数据 <BR>  &acute;c:\forwin95\win.ini&acute;&nbsp;//&nbsp;调用的文件名 <BR>  ); <BR>  上面的方法是调用API函数,下面介绍另一种不用API从.INI文件中获取字符的方法 <BR>  var&nbsp;MyIni:&nbsp;TIniFile; <BR>  begin <BR>  MyIni&nbsp;:=&nbsp;TIniFile.Create(&acute;WIN.INI&acute;);//调用的文件名 <BR>  edit1.text:=MyIni.ReadString(&acute;Desktop&acute;,&nbsp;&acute;Wallpaper&acute;,&nbsp;&acute;&acute;);//取得字符 <BR>  end; <BR>  向.INI文件中写入字符的方法 <BR>  var&nbsp;MyIni:&nbsp;TIniFile; <BR>  begin <BR>  MyIni&nbsp;:=&nbsp;TIniFile.Create(&acute;WIN.INI&acute;);//调用的文件名 <BR>  DelphiIni.WriteString(&acute;Desktop&acute;,&nbsp;&acute;Wallpaper&acute;,&nbsp;&acute;c:\a.bmp&acute;); <BR>  end;
                           
                            <div class="art_xg">
                              <b>您可能感兴趣的文章:</b><ul><li>Delphi实现木马文件传输代码实例</li><li>Delphi用TActionList实现下载文件的方法</li><li>Delphi中判断文件是否为文本文件的函数</li><li>Delphi建立、读取、存贮INI文件的方法《一》</li><li>delphi建立、读取、存贮INI文件的方法《二》</li><li>delphi制作wav文件的方法</li></ul>
                            </div>

                        </div>
                        <!--endmain-->
頁: [1]
查看完整版本: delphi建立、读取、存贮INI文件的方法《三》