fini := TMemIniFile.Create('params.ini');
s := fini.ReadString('section','param1','');
s becomes '' although there is this section in the file params.ini:
[section]
param1=ABCDE
However, when fini is of type TIniFile, all is well and s becomes
'ABCDE' as it should.
Shouldn't this just work with a TMemIniFile too, or have I missed
something?
(Apologies if this is a FAQ, I couldn't find it)
Regards,
Arjan
Yes, they work differently if the file name does not contain full path.
TIniFile uses GetPrivateProfileString which looks for the file in Windows
directory. TMemIniFile uses FileExists and TStringList.LoadFromFile
which look for the file in the current directory.
Igor
I modified my call to TMemIniFile.Create to use the full path.
It doesn't make any difference.
Regards,
Arjan
Examine the content of the file that TMemIniFile loads by using
methods such as GetStrings, ReadSections, ReadSections, ReadSectionValues.
Igor
Arjan wrote:
> There seems to be a difference between TIniFile and TMemIniFile that I
> wasn't aware of.
>
>
> fini := TMemIniFile.Create('params.ini');
> s := fini.ReadString('section','param1','');
>
> s becomes '' although there is this section in the file params.ini:
>
> [section]
> param1=ABCDE
>
> However, when fini is of type TIniFile, all is well and s becomes
> 'ABCDE' as it should.
> Shouldn't this just work with a TMemIniFile too, or have I missed
> something?
At least for D7, TMemIniFile doesn't work with UTF-16 coded files
("Unicode") while TIniFile does. Perhaps that's your problem?
HTH,
Patrick
Groan, I didn't know that. Yes, I am using D7 - this might well be the
problem.
Thanks for all the replies!
Regards,
Arjan
I also found it out the hard way... upgraded some program that writes ini
files which still looked the same at the first glance but suddenly my
program stopped working.
Bye, Patrick
Oh ehm... writing works for me, only reading does not.
Anyway, I am using TMemIniFiles for writing (because they're faster)
and TIniFiles for reading now. Clumsy, but it works.
Regards,
Arjan
No, you misunderstood me. The upgraded program was a different application
I didn't write and which originally wrote normal ASCII .ini-Files, then it
suddenly started writing UTF-16 files. My program had to read these files.
Sorry, "some program" was abiguous.
Have a nice weekend!
Patrick