<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:Tahoma
}
--></style>
</head>
<body class='hmmessage'>
<div><font class="Apple-style-span" face="Tahoma" size="2">Hi All, </font></div><div><font class="Apple-style-span" face="Tahoma" size="2"><br></font></div><div><font class="Apple-style-span" face="Tahoma" size="2">I use this procedure to save an inifile using the standard IniFiles unit. The problem I have is that when an .ini file already exists I cannot overwrite it. I need the TextFiles equivalent of Rewrite() for Inifiles.</font></div><div><font class="Apple-style-span" face="Tahoma" size="2"><br></font></div><div><font class="Apple-style-span" face="Tahoma" size="2">This line:</font></div><div><font class="Apple-style-span" face="Tahoma" size="2"><div style="text-indent: 0px !important; font-family: 'Times New Roman'; font-size: medium; "><font class="Apple-style-span" face="Tahoma" size="2" style="text-indent: 0px !important; "> ConfigIni := TIniFile.Create(ChangeFileExt(Application.ExeName, '.ini'));</font></div><div><font class="Apple-style-span" face="Tahoma" size="2" style="text-indent: 0px !important; ">... when the ini file exists fails with an error message of 'unable to create appname.ini'. This is because it cannot create an ini file which already exists.</font></div><div><font class="Apple-style-span" face="Tahoma" size="2" style="text-indent: 0px !important; "><br></font></div><div><font class="Apple-style-span" face="Tahoma" size="2" style="text-indent: 0px !important; ">How then do I rewrite the .ini file?</font></div><div><font class="Apple-style-span" face="Tahoma" size="2" style="text-indent: 0px !important; "><br></font></div><div><font class="Apple-style-span" face="Tahoma" size="2" style="text-indent: 0px !important; ">Uses IniFiles;</font></div><div><font class="Apple-style-span" face="Tahoma" size="2" style="text-indent: 0px !important; "><br></font></div><div>procedure TMain_Form.SaveIniFile;</div></font></div><div><font class="Apple-style-span" face="Tahoma" size="2">var</font></div><div><font class="Apple-style-span" face="Tahoma" size="2"> ConfigIni: TIniFile;</font></div><div><font class="Apple-style-span" face="Tahoma" size="2"> x, y: integer;</font></div><div><font class="Apple-style-span" face="Tahoma" size="2">begin</font></div><div><font class="Apple-style-span" face="Tahoma" size="2"> ConfigIni := TIniFile.Create(ChangeFileExt(Application.ExeName, '.ini'));</font></div><div><font class="Apple-style-span" face="Tahoma" size="2"> // e.g. fred.exe becomes fred.ini</font></div><div><font class="Apple-style-span" face="Tahoma" size="2"> try</font></div><div><font class="Apple-style-span" face="Tahoma" size="2"> for x := 1 to max_pats do</font></div><div><font class="Apple-style-span" face="Tahoma" size="2"> begin</font></div><div><font class="Apple-style-span" face="Tahoma" size="2"> if patterns_list[x].Count > 0 then</font></div><div><font class="Apple-style-span" face="Tahoma" size="2"> begin</font></div><div><font class="Apple-style-span" face="Tahoma" size="2"> ConfigIni.WriteString('Pattern' + inttostr(x), 'Name', Patterns_list[x].Strings[0]);</font></div><div><font class="Apple-style-span" face="Tahoma" size="2"> for y := 1 to patterns_list[x].Count - 1 do</font></div><div><font class="Apple-style-span" face="Tahoma" size="2"> ConfigIni.WriteString('Pattern' + inttostr(x), 'Line' + inttostr(y), Patterns_list[x].Strings[y]);</font></div><div><font class="Apple-style-span" face="Tahoma" size="2"> end;</font></div><div><font class="Apple-style-span" face="Tahoma" size="2"> end;</font></div><div><font class="Apple-style-span" face="Tahoma" size="2"><br></font></div><div><font class="Apple-style-span" face="Tahoma" size="2"> ConfigIni.WriteInteger('General', 'Auto Generation Delay', Timer1.Interval);</font></div><div><font class="Apple-style-span" face="Tahoma" size="2"> if current_color_scheme = krgy then</font></div><div><font class="Apple-style-span" face="Tahoma" size="2"> ConfigIni.WriteString('General', 'Current Color Scheme', 'krgy')</font></div><div><font class="Apple-style-span" face="Tahoma" size="2"> else</font></div><div><font class="Apple-style-span" face="Tahoma" size="2"> ConfigIni.WriteString('General', 'Current Color Scheme', 'kmcw');</font></div><div><font class="Apple-style-span" face="Tahoma" size="2"> ConfigIni.WriteBool('General', 'Sound Wanted', Sound_wanted);</font></div><div><font class="Apple-style-span" face="Tahoma" size="2"><br></font></div><div><font class="Apple-style-span" face="Tahoma" size="2"> ConfigIni.UpdateFile;</font></div><div><font class="Apple-style-span" face="Tahoma" size="2"> finally</font></div><div><font class="Apple-style-span" face="Tahoma" size="2"> ConfigIni.Free;</font></div><div><font class="Apple-style-span" face="Tahoma" size="2"> end;</font></div><div><font class="Apple-style-span" face="Tahoma" size="2">end;</font></div><div><font class="Apple-style-span" face="Tahoma" size="2">{---------------------------------------------------------}</font></div><div style="font-family: Tahoma; font-size: 10pt; "><br></div><div style="font-family: Tahoma; font-size: 10pt; ">Best Regards,</div><div style="font-family: Tahoma; font-size: 10pt; ">Peter / pew</div> </body>
</html>