Reading a value without using sections

How can I read a value from INI without using partitions?
Therefore, instead of the usual file:

[section] name=value 

this will result in the following:

 name=value 
+4
source share
3 answers

Then I would not call it an INI file. Anyway, the TStringList class is perfect for this.

Consider the animals.txt file:

 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; 
+8
source

There is a good tutorial here. For example, if iniFile is an instance of TIniFile , you can call the iniFile.ReadString method with an empty section pointer.

+2
source

I think that in fact the question needs additional information. Often people ask questions regarding what they think they need to do, instead of asking questions related to what they are actually trying to accomplish.

Why do you need this instead of the usual ini read methods? If they are existing ini files, you should use Tinifile.ReadSections to read the section names into a string list, and then iterate through this list with Tinifile.ReadSectionValues to read all the section name / value pairs.

Do you read existing INI files or read and write your own files? If these are your own files, then Andreas has a good answer above.

-one
source

Source: https://habr.com/ru/post/1397320/


All Articles