Knowing how many properties an INI session has?

2

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

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

In the example above there are 3 properties.

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

    
asked by anonymous 08.07.2015 / 18:29

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 the click of a button that does what you want:

  • Shows how many keys exist;
  • Show their contents;
17.07.2015 / 20:13
1

It can be done as follows, create a new project enter a TButton and a TMemo and in the event onclick of 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 question please.

    
25.10.2016 / 18:34