Question

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 ?

Was it helpful?

Solution 2

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.

OTHER TIPS

TIniFile is a wrapper around the Windows API calls to read/write INI Files, and thus, are limited of what is supported by the Windows API, specially for GetPrivateProfileString

AFAIK There's no formal definition of the file format, and, as you just discovered, duplicate keys are not supported by Microsoft implementation, since the function returns always the first occurrence.

If you look close at the ReadSectionValues implementation, you will notice it first read the section keys and then retrieve the key values in a loop, since that's the way to go with the mentioned GetPrivateProfileString function, and thus it is getting the same value for all the calls.

My advice is to stop using TIniFile to read files that are not INI files.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top