Know how many properties an INI session has?

Asked

Viewed 924 times

2

I have an INI file which a session has several properties:

[DLLS]
Dll1=...
Dll2=...
Dll3=...

In the above example there are 3 properties.

Is there any method in the Delphi to identify how many properties a session [DLLS] has?

2 answers

2

procedure TForm1.Button1Click(Sender: TObject);
    var
      MeuINI : TIniFile;
      strValores : TStringList;
    begin   
      MeuINI := TIniFile.Create('Z:\Temp\Teste.ini');
      MeuINI.UpdateFile;
      strValores := TStringList.Create;

      if MeuINI.SectionExists('DLLS') then
        MeuINI.ReadSection('DLLS',strValores);

      ShowMessage(IntToStr(strValores.Count));
      ShowMessage(strValores.Text);   
    end;

Example of a button click that does what you want:

  • Shows how many keys there are;
  • Shows their contents;

1

Can be done as follows, creates a new project insert a TButton and a TMemo and at the event onclick From the button paste the following code:

procedure TForm1.Btn1Click(Sender: TObject);
var VCount: TStringList;
    INI: TiniFile;
begin
  VCount := TStringList.Create;

  INI := TIniFile.Create('c:\test.ini');
    if INI.SectionExists('DLLS') then INI.ReadSection('DLLS', VCount);
  INI.Free;

  memo1.Lines.Add(IntToStr(VCount.Count));
end;

Any doubt put.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.