开发者

Reset Ini files button delphi

I want to create a reset button for my delphi program. In my program sometimes ther开发者_开发百科e are some Ini. files created in the pathexe. What I want to do is now create a button or a tab that lets me click on it and when it does. It deletes all the .Ini files in my pathexe

How could I do this?

Also I want to know how to make a little 'Are you sure?' pop up, but that's a minor detail.


You should do something like

  if MessageBox(Handle, 'Are you sure you want to restore the default settings?',
    PChar(Caption), MB_ICONQUESTION or MB_YESNO) = ID_YES then
  begin
    DeleteFile(SettingsFileName);
    LoadSettings;
  end;

where SettingsFileName is the file name of the INI file (which resides in a per-user location), and LoadSettings is the procedure that you use to load the settings from the INI file (which, of course (!), applies the default settings should there be no INI file).


Code below uses uses wildcard to get list of ini files and delete one by one.

procedure DeleteIni();
var searchResult : TSearchRec;
begin
  if FindFirst('*.ini', faAnyFile, searchResult) = 0 then
  begin
    repeat
      DeleteFile(searchResult.Name);
    until FindNext(searchResult) <> 0;
    FindClose(searchResult);
  end;
end;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜