Board index » delphi » Strange thing: update INI fails???

Strange thing: update INI fails???

Hi!
I have some strange things.. Well, I have a procedure which works with INI,
writes data into it, then closes it, and then renames it. See the changes:
first.ini:
[common]
a=5

Then ->  Ini.WriteString('common','a','3');
Then -> Ini.Free

And when I make RenameFile('first.ini','second.ini'), the file second.ini
contains:

[common]
a=5

And first.ini is not deleted!!! It contains:

[common]
a=3

I have it all in one procedure. I think maybe computer didn't have time to
update my file. And sometimes I will get this error, sometimes I won't get
it. And when I call FileExists('first.ini') it returns False, while in the
WinCommander I can see and edit it!!! What should i do??? Have I somehow
flush buffers or something like that to force computer to update file
changes? thank you for advance.

Jevgenij Gorbunov - gorbu...@med.muni.cz
----------------------------------------------------------------------------
Czech Republic, Brno. ICQ: 11471114.
Medicine, computers, translations, ...
----------------------------------------------------------------------------
Anyone sending me unsolicited/commercial/junk/spam e-mail
will be MAILBOMBED. So think before you act...
----------------------------------------------------------------------------

 

Re:Strange thing: update INI fails???


If you could post the procedure we could test it and possibly find the
problem for you. Right now (still waking up and in desperate need of sleep)
I don't see what could be wrong. post the procedure and I'll test it

Roel

Quote
Jevgenij Gorbunov <gorbu...@med.muni.cz> wrote:

: Hi!

<snip of original post done as I think of modem users ;)>

Re:Strange thing: update INI fails???


Well I won't post it because it is huge (30 Kb - think about modem
users...). But now I think I have corrected it, but in a strange way. See
what I changed.

Before it was:
1) Read values from 1.ini
2) Write values to 1.ini
3) Renaming 1.ini to 2.ini
4) Boom! 2.ini cantains old data (which were in the 1.ini before step 2

Now it is:
1) Read values from 1.ini
2) Renaming 1.ini to 2.ini
3) Write values to 2.ini
4) Everything is OK.

But I don't understand what it was... Anyway I pray not to encounter this
problem in the future...

Jevgenij Gorbunov - gorbu...@med.muni.cz
----------------------------------------------------------------------------
Czech Republic, Brno. ICQ: 11471114.
Medicine, computers, translations, ...
----------------------------------------------------------------------------
Anyone sending me unsolicited/commercial/junk/spam e-mail
will be MAILBOMBED. So think before you act...
----------------------------------------------------------------------------

Roel Spapens D??? ???Y?? <6l5fs6$qq...@turtle.stack.nl> ...

Quote
>If you could post the procedure we could test it and possibly find the
>problem for you. Right now (still waking up and in desperate need of sleep)
>I don't see what could be wrong. post the procedure and I'll test it

>Roel

>Jevgenij Gorbunov <gorbu...@med.muni.cz> wrote:
>: Hi!

><snip of original post done as I think of modem users ;)>

Re:Strange thing: update INI fails???


Jevgenij,

The problem is that you're not supposed to mix calls to the
Windows INI file routines (which are what TIniFile uses) and
regular file operations. The reason is that Windows caches the
ini file in memory to improve performance, and may take quite
a long time to write it out to disk.

HTH

Ken
--
Ken White
kwh...@westelcom.com

Clipper Functions for Delphi
http://members.aol.com/clipfunc/

Quote
Jevgenij Gorbunov wrote:

> Hi!
> I have some strange things.. Well, I have a procedure which works with INI,
> writes data into it, then closes it, and then renames it. See the changes:
> first.ini:
> [common]
> a=5

> Then ->  Ini.WriteString('common','a','3');
> Then -> Ini.Free

> And when I make RenameFile('first.ini','second.ini'), the file second.ini
> contains:

> [common]
> a=5

> And first.ini is not deleted!!! It contains:

> [common]
> a=3

> I have it all in one procedure. I think maybe computer didn't have time to
> update my file. And sometimes I will get this error, sometimes I won't get
> it. And when I call FileExists('first.ini') it returns False, while in the
> WinCommander I can see and edit it!!! What should i do??? Have I somehow
> flush buffers or something like that to force computer to update file
> changes? thank you for advance.

> Jevgenij Gorbunov - gorbu...@med.muni.cz
> ----------------------------------------------------------------------------
> Czech Republic, Brno. ICQ: 11471114.
> Medicine, computers, translations, ...
> ----------------------------------------------------------------------------
> Anyone sending me unsolicited/commercial/junk/spam e-mail
> will be MAILBOMBED. So think before you act...
> ----------------------------------------------------------------------------

Re:Strange thing: update INI fails???


On Fri, 05 Jun 1998 16:21:29 -0400, Ken White <kwh...@westelcom.com>
wrote:

Quote
>Jevgenij,

>The problem is that you're not supposed to mix calls to the
>Windows INI file routines (which are what TIniFile uses) and
>regular file operations. The reason is that Windows caches the
>ini file in memory to improve performance, and may take quite
>a long time to write it out to disk.

Besides, why do you feel the need to rename a .ini file?

Re:Strange thing: update INI fails???


Ken White ??? a ???? <35785349.1708E...@westelcom.com> ...

Quote
>Jevgenij,

>The problem is that you're not supposed to mix calls to the
>Windows INI file routines (which are what TIniFile uses) and
>regular file operations. The reason is that Windows caches the
>ini file in memory to improve performance, and may take quite
>a long time to write it out to disk.

Hi Ken!
What do you think, can I force Windows to flush cache on disk somehow to
make my files immediately ready? I tried many things, like
assignfile;reset;closefile; but it didn't work. I even tried to copy my
changed ini file - it didn't work either. I tried to put some
Application.ProcessMessages to give w95 possibility to flush cache - no
result. As I said, the only working model is to rename file BEFORE changing
it, and then make changes in that new file. But it seems to me a bit
perverse method. I searched for something like "WriteCache" proc in the
win32.hlp - no result. Can I do something with it? Also I am wondering about
this situation - in my humble opinion, windoz must control file/cache
operations so the file must be prepared when I wanna work with it. Am I
right?

Jevgenij Gorbunov - gorbu...@med.muni.cz
----------------------------------------------------------------------------
Czech Republic, Brno. ICQ: 11471114.
Medicine, computers, translations, ...
----------------------------------------------------------------------------
Anyone sending me unsolicited/commercial/junk/spam e-mail
will be MAILBOMBED. So think before you act...
----------------------------------------------------------------------------

Re:Strange thing: update INI fails???


Quote
>Besides, why do you feel the need to rename a .ini file?

It does not matter so much. As a human I am expecting from computer that it
will listen me and do what I want to do. When I want to rename ini file (or
anything else), the computer just must do it, no matter why.

Greetings,

Jevgenij Gorbunov - gorbu...@med.muni.cz
----------------------------------------------------------------------------
Czech Republic, Brno. ICQ: 11471114.
Medicine, computers, translations, ...
----------------------------------------------------------------------------
Anyone sending me unsolicited/commercial/junk/spam e-mail
will be MAILBOMBED. So think before you act...
----------------------------------------------------------------------------

Re:Strange thing: update INI fails???


On Sun, 7 Jun 1998 10:55:40 GMT, "Jevgenij Gorbunov"

Quote
<gorbu...@med.muni.cz> wrote:
>>Besides, why do you feel the need to rename a .ini file?

>It does not matter so much. As a human I am expecting from computer that it
>will listen me and do what I want to do. When I want to rename ini file (or
>anything else), the computer just must do it, no matter why.

Hell, sometimes I'd like my computer to find me a date, but it won't
do so EVEN THOUGH I INSIST. <grin>

The thing is that people often ask me how to do certain things.
Sometimes, when what they want to do sounds a little strange, I'll ask
why they want to do it. When they tell me, I often find that they're
on the wrong track, and that there is a better way to accomplish what
they really mean to do. Obviously, you're not interested in that kind
of assistance. Oh, well.

To answer your question:

You can force Windoze to flush the .ini buffer by using the WinAPI
call

WriteProfileString('','','');

After that, you can rename the .ini as you please.

Re:Strange thing: update INI fails???


JG,

Quote
> What do you think, can I force Windows to flush cache on disk somehow

See the reply from {*word*104}Cat immediately above this one; he explained
how to flush INI files to disk.

Quote
> this situation - in my humble opinion, windoz must control file/cache
> operations so the file must be prepared when I wanna work with it. Am I
> right?

You're right, and Windows does control the cache so files are ready
when you access them (except for INI files)...

Ken
--
Ken White
kwh...@westelcom.com

Clipper Functions for Delphi
http://members.aol.com/clipfunc/

Other Threads