如何用INI文件记录程序设置?(40分)

  • 主题发起人 主题发起人 uranium235
  • 开始时间 开始时间
U

uranium235

Unregistered / Unconfirmed
GUEST, unregistred user!
请给出实例程序,谢谢——40分相送。
 
Uses inifiles;<br><br><br>例1、<br>&nbsp; &nbsp; &nbsp; Ini := TIniFile.Create(ParamStr(1));<br>&nbsp; &nbsp; &nbsp; try<br>&nbsp; &nbsp; &nbsp; &nbsp; OutputFileName := Ini.ReadString('System','Output File',''); {do not localize}<br>&nbsp; &nbsp; &nbsp; finally<br>&nbsp; &nbsp; &nbsp; &nbsp; Ini.Free;<br>&nbsp; &nbsp; &nbsp; end;<br><br><br><br><br><br>例2、<br>&nbsp; FIniFile := TIniFile.Create(IniFileName);<br>&nbsp; if ContentFile = '' then<br>&nbsp; &nbsp; ContentFile := FIniFile.ReadString('System', 'Content File', 'ContentFile');<br>&nbsp; if OutputFile = '' then<br>&nbsp; &nbsp; OutputFile := FIniFile.ReadString('System', 'Output File', 'OutputFile.html');<br>&nbsp; FIniFile.Free;<br><br><br>例3:<br>&nbsp; RSCON: TIniFile;<br>begin<br>&nbsp;{ the ReportSmith CON file is actually an INI file -- assumes in win dir}<br>&nbsp; RSCon := TIniFile.Create(TiniFilename);<br>&nbsp; TempStr := RSCon.ReadString(ConnectNamesSection, ConnectNamesKey, '');<br>&nbsp; { CON file contents differs for SQL connections }<br>&nbsp; if MastData.Database.IsSQLBased then<br>&nbsp; begin<br>&nbsp; &nbsp; if AnsiPos(SQLConTitle,TempStr) = 0 then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; if TempStr &lt;&gt; '' then<br>&nbsp; &nbsp; &nbsp; &nbsp; TempStr := TempStr + ',';<br>&nbsp; &nbsp; &nbsp; RSCon.WriteString(ConnectNamesSection, ConnectNamesKey, TempStr+SQLConTitle);<br>&nbsp; &nbsp; end;<br>&nbsp; &nbsp; RSCon.WriteInteger(MASTSQLSection, TypeKey, SQLTypeVal);<br>&nbsp; &nbsp; RSCon.WriteString(MASTSQLSection, SQLDataFilePathKey, DBpath);<br>&nbsp; &nbsp; RSCon.WriteString(MASTSQLSection, ServerKey, SQLServerVal);<br>&nbsp; &nbsp; RSCon.WriteString(MASTSQLSection, SQLUseridKey, SQLUseridVal);<br>&nbsp; end<br>&nbsp; else<br>&nbsp; begin<br>&nbsp; &nbsp; if AnsiPos(AppConTitle,TempStr) = 0 then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; if TempStr &lt;&gt; '' then<br>&nbsp; &nbsp; &nbsp; &nbsp; TempStr := TempStr + ',';<br>&nbsp; &nbsp; &nbsp; RSCon.WriteString(ConnectNamesSection, ConnectNamesKey, TempStr+AppConTitle);<br>&nbsp; &nbsp; end;<br>&nbsp; &nbsp; RSCon.WriteInteger(MASTAPPSection, TypeKey, TypeVal);<br>&nbsp; &nbsp; RSCon.WriteString(MASTAPPSection, DataFilePathKey, DBpath);<br>&nbsp; &nbsp; RSCon.WriteString(MASTAPPSection, ServerKey, ServerVal);<br>&nbsp; end;<br>&nbsp; RSCon.Free;<br>
 
接受答案了.
 
后退
顶部