Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6247423
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T12:52:05+00:00 2026-05-24T12:52:05+00:00

When an ini file contains a section with only one key (like MySection1 in

  • 0

When an ini file contains a section with only one key (like MySection1 in

[MySection1]
MyKey1=MyValue1
[MySection2]
...

) calling DeleteKey for that key leaves an empty section:

[MySection1]
[MySection2]
...

I’d prefer if that empty section would be removed too. Of course I can call something like

if not ini.SectionExists('MySection1') then
  ini.EraseSection('MySection1');

after every call to DeleteKey (or make an overridden TExtIniFile.DeleteKey do that) but I hope there is an automatic way to make Windows or the VCL do that. Do you know any?

Update: I’m using a TIniFile descendant that solely adds some additional Read*/Write* methods.

Update: My test routine:

procedure TForm1.Button1Click(Sender: TObject);
var
  ini: TMyIniFile;
begin
  ini := TMyIniFile.Create(cIniFileName);
  try
    ini.WriteString('MySection1', 'MyKey1', 'MyValue1');
    ini.DeleteKey('MySection1', 'MyKey1');
  finally
    ini.Free;
  end;

  Show;
end;

procedure TForm1.Show;
begin
  if FileExists(cIniFileName) then
    Memo1.Lines.LoadFromFile(cIniFileName)
  else
    Memo1.Lines.Clear;
end;

TMyIniFile can be an alias for TIniFile or a descendant of TMemIniFile with an destructor calling UpdateFile.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T12:52:06+00:00Added an answer on May 24, 2026 at 12:52 pm

    I don’t think there is “automatic way to make Windows or the VCL do that”. I believe that the reason is that “API” doesn’t know that you don’t intend to use that section anymore (ie if the API would delete the section after you delete the last key someone would complain that this is inefficient as they intend to add an key to that section later and so the section must be recreated). Also, one could argue that the existence of the empty section carries information too and thus that information would be lost in case of automatic deletion.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a ini file which contains some sample values like: [Section1] Value1 =
Each Pyramid application has an associated .ini file that contains its settings. For example,
I have an INI file that I want to read the line DeviceName=PHJ01444-MC35 from
I have text files that are Tab delimited. I created a Schema.ini like so:
I'm loading an ini file with boost property_tree. My ini file mostly contains simple
I'm building a routine that creates a settings.ini file from a database table. I
I have ini file that I read in my program. The ini file need
I have a file which contains two JSON arrays; one is holding the column
I have a .ini file with sensitive information in my php wab app. I
I'm trying to parse an INI file using C++. Any tips on what is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.