Search code examples
delphiiniinf

How to read a inf file?


I used TiniFile to read a inf file . but in some section the ident is same , TiniFile can't read it.

for example :

this section :

[AMD.Mfg]
%AMD.DeviceDesc0% = AMDSMBus, PCI\VEN_1002&DEV_4353
%AMD.DeviceDesc0% = AMDSMBus, PCI\VEN_1002&DEV_4363
%AMD.DeviceDesc0% = AMDSMBus, PCI\VEN_1002&DEV_4372
%AMD.DeviceDesc0% = AMDSMBus, PCI\VEN_1002&DEV_4385
%AMD.DeviceDesc0% = AMDSMBus, PCI\VEN_1022&DEV_780B

my code :

    var
      inf : TiniFile;
      list : TStringList;
    begin
      //Create
      inf := TIniFile.Create(infPath);
      list := TStringList.Create;  
      inf.ReadSectionValues('AMD.Mfg', list);
      Memo1.Lines.AddStrings(list2);
    end;

it display this :

%AMD.DeviceDesc0%=AMDSMBus, PCI\VEN_1002&DEV_4353
%AMD.DeviceDesc0%=AMDSMBus, PCI\VEN_1002&DEV_4353
%AMD.DeviceDesc0%=AMDSMBus, PCI\VEN_1002&DEV_4353
%AMD.DeviceDesc0%=AMDSMBus, PCI\VEN_1002&DEV_4353
%AMD.DeviceDesc0%=AMDSMBus, PCI\VEN_1002&DEV_4353

I guess the same ident cause this , so my question is how to read it when ident is same ?


Solution

  • You're very vague what you mean by "read". Actually you can read that file by any lots of means Delphi has. Personally i'd read it using TStringList.LoadFromFile

    The question is what would you do after you read it...

    You may also try ur chances with TMemIniFile to do it. But i'd personally certainly avoided any INI-related methods, for those files are strongly deviating fro mbasic INI premise and any INI-related library may change its implementation at any upgrade ruining the program using it.