[Lazarus] Unable to rewrite .ini file which exists... error unable to create .ini file. (need to rewrite it).
ik
idokan at gmail.com
Tue Mar 15 08:08:30 CET 2011
2011/3/15 Peter Williams <pewilliams2010 at live.com>
> Hi All,
>
> 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.
>
> This line:
> ConfigIni := TIniFile.Create(ChangeFileExt(Application.ExeName, '.ini'));
> ... 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.
>
> How then do I rewrite the .ini file?
>
> Uses IniFiles;
>
> procedure TMain_Form.SaveIniFile;
> var
> ConfigIni: TIniFile;
> x, y: integer;
> begin
> ConfigIni := TIniFile.Create(ChangeFileExt(Application.ExeName, '.ini'));
> // e.g. fred.exe becomes fred.ini
> try
> for x := 1 to max_pats do
> begin
> if patterns_list[x].Count > 0 then
> begin
> ConfigIni.WriteString('Pattern' + inttostr(x), 'Name',
> Patterns_list[x].Strings[0]);
> for y := 1 to patterns_list[x].Count - 1 do
> ConfigIni.WriteString('Pattern' + inttostr(x), 'Line' +
> inttostr(y), Patterns_list[x].Strings[y]);
> end;
> end;
>
> ConfigIni.WriteInteger('General', 'Auto Generation Delay',
> Timer1.Interval);
> if current_color_scheme = krgy then
> ConfigIni.WriteString('General', 'Current Color Scheme', 'krgy')
> else
> ConfigIni.WriteString('General', 'Current Color Scheme', 'kmcw');
> ConfigIni.WriteBool('General', 'Sound Wanted', Sound_wanted);
>
> ConfigIni.UpdateFile;
> finally
> ConfigIni.Free;
> end;
> end;
> {---------------------------------------------------------}
>
> Best Regards,
> Peter / pew
>
> --
> _______________________________________________
> Lazarus mailing list
> Lazarus at lists.lazarus.freepascal.org
> http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
>
>
Do you have permission for writing the content of the file ?
Ido
LINESIP - Opening the source for communication
http://www.linesip.com
http://www.linesip.co.il
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20110315/7c670a81/attachment-0007.html>
More information about the Lazarus
mailing list