Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reading value without using sections

How do I read value from INI file without using sections?
So instead of normal file:

[section]
name=value

it would result in this:

name=value
like image 523
Little Helper Avatar asked Dec 28 '22 05:12

Little Helper


1 Answers

I wouldn't call it an INI file, then. Anyhow, for this the TStringList class fits perfectly.

Consider the file animals.txt:

dog=Sally
rat=Fiona
cat=Linus

And consider this code:

procedure TForm1.Button1Click(Sender: TObject);
begin
  with TStringList.Create do
    try
      LoadFromFile('C:\Users\Andreas Rejbrand\Desktop\animals.txt');
      ShowMessage(Values['dog']);
    finally
      Free;
    end;
end;
like image 177
Andreas Rejbrand Avatar answered Jan 12 '23 04:01

Andreas Rejbrand