Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

TMemIniFile reading problem

613 views
Skip to first unread message

Arjan

unread,
Aug 9, 2006, 11:00:55 AM8/9/06
to
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?
(Apologies if this is a FAQ, I couldn't find it)


Regards,
Arjan


Igor Raskin

unread,
Aug 9, 2006, 11:24:03 AM8/9/06
to
"Arjan" <ar...@example.com> wrote in message
news:44d9...@newsgroups.borland.com...

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


Arjan

unread,
Aug 9, 2006, 11:31:20 AM8/9/06
to

"Igor Raskin" <igorr@web_lakes.com> wrote in message
news:44d9fe11$1...@newsgroups.borland.com...


I modified my call to TMemIniFile.Create to use the full path.
It doesn't make any difference.


Regards,
Arjan


Igor Raskin

unread,
Aug 9, 2006, 11:36:59 AM8/9/06
to

Examine the content of the file that TMemIniFile loads by using
methods such as GetStrings, ReadSections, ReadSections, ReadSectionValues.

Igor


Patrick Kursawe

unread,
Aug 10, 2006, 2:53:12 AM8/10/06
to
Hi there,

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

Arjan

unread,
Aug 10, 2006, 7:15:14 AM8/10/06
to
"Patrick Kursawe" <patrick...@web.de> wrote in message
news:44da...@newsgroups.borland.com...
> Hi there,
>
> Arjan wrote:
> > [snip TMemIniFile ReadString problem]

>
>
> At least for D7, TMemIniFile doesn't work with UTF-16 coded files
> ("Unicode") while TIniFile does. Perhaps that's your problem?


Groan, I didn't know that. Yes, I am using D7 - this might well be the
problem.

Thanks for all the replies!


Regards,
Arjan


Patrick Kursawe

unread,
Aug 10, 2006, 8:29:04 AM8/10/06
to
Arjan wrote:
[TMemIniFile not UTF-16 enabled]

> Groan, I didn't know that. Yes, I am using D7 - this might well be the
> problem.

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

Arjan

unread,
Aug 11, 2006, 8:55:55 AM8/11/06
to
"Patrick Kursawe" <patrick...@web.de> wrote in message
news:44db...@newsgroups.borland.com...


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


Patrick Kursawe

unread,
Aug 11, 2006, 9:20:26 AM8/11/06
to
Arjan wrote:
> "Patrick Kursawe" <patrick...@web.de> wrote in message
> news:44db...@newsgroups.borland.com...
>> Arjan wrote:
>> [TMemIniFile not UTF-16 enabled]
>>> Groan, I didn't know that. Yes, I am using D7 - this might well be
>>> the problem.
>> 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.
>
>
> Oh ehm... writing works for me, only reading does not.

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

0 new messages