[Lazarus] Unable to rewrite .ini file which exists... error unable to create .ini file. (need to rewrite it).
Peter Williams
pewilliams2010 at live.com
Tue Mar 15 05:25:41 CET 2011
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20110315/158dcc44/attachment-0002.html>
More information about the Lazarus
mailing list