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
[email protected]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply via email to