Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Problem with TIniFile


This question is answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 6 - Last Post: Dec 4, 2015 1:55 AM Last Post By: David Ayre
David Ayre

Posts: 34
Registered: 10/11/00
Problem with TIniFile  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 27, 2015 3:28 AM
I have a strange problem using TIniFile.
When the programme opens a screen, it does a number of initialisations
including reading a value from an ini file.
It must have this value, so I have put it into a loop that continuously
reads the file until it gets a valid result. ie a number. If it
fails to read for some reason, it return a zero. This routine is used on
quite a few computers and normally works well. However, I have had
someone recently who has just upgraded his system and he finds that
when he runs the programme from one of his older computers, with the
data on the new one, it takes about 17 seconds to start up instead of
less than a second, which is usual.
I can only think that it is unable to read the ini file initially but eventually
manages after multiple attempts.
If anyone can shed any light on this problem I would be very grateful.

Cheers,

David Ayre
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: Problem with TIniFile  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 28, 2015 4:26 PM   in response to: David Ayre in response to: David Ayre
David wrote:

It must have this value, so I have put it into a loop that
continuously reads the file until it gets a valid result.

Why are you looping it? Are you really expecting TIniFile reading methods
to not return a value when you ask for one the first time? Also, have you
considered using TMemIniFile instead of TIniFile?

However, I have had someone recently who has just upgraded
his system and he finds that when he runs the programme from
one of his older computers, with the data on the new one, it
takes about 17 seconds to start up instead of less than a
second, which is usual.

Does your loop do any sleeping between iterations? Have you tried using
a utility app such as SysInternals ProcessMonitor to watch the file activity
in real time to see just how fast the app is reading the file? Maybe the
HDD is encountering delays reading its sectors.

--
Remy Lebeau (TeamB)
David Ayre

Posts: 34
Registered: 10/11/00
Re: Problem with TIniFile  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 29, 2015 10:53 AM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Hi Remy,

Why are you looping it? Are you really expecting TIniFile reading methods
to not return a value when you ask for one the first time? Also, have you
considered using TMemIniFile instead of TIniFile?

I have found on odd occasions that the next Order Number has not been
read, so I have put a loop in to give it another try. Maybe this is a bit clumsy
but it has always worked in the past. Until now I have never known it wait for
17 seconds before reading it, and I don't know why it would.

What is the difference between TIniFile and TMemIniFile?

Does your loop do any sleeping between iterations?

No. It is just a loop that continues as long as a zero is returned.

Cheers,

David

Edited by: David Ayre on Nov 29, 2015 10:54 AM
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: Problem with TIniFile [Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 30, 2015 11:14 AM   in response to: David Ayre in response to: David Ayre
David wrote:

What is the difference between TIniFile and TMemIniFile?

TIniFile simply uses Win32 INI functions to read/write data directly from/to
the INI file.

TMemIniFile does all reading/writing in memory. An INI file is loaded into
memory, data is read from memory, changes are written to memory, and the
INI file is updated when you call the UpdateFile() method.

Also, TIniFile does not support Unicode INI files, but TMemIniFile does.

--
Remy Lebeau (TeamB)
David Ayre

Posts: 34
Registered: 10/11/00
Re: Problem with TIniFile [Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 3, 2015 2:50 AM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
TMemIniFile does all reading/writing in memory. An INI file is loaded into
memory, data is read from memory, changes are written to memory, and the
INI file is updated when you call the UpdateFile() method.

Thanks Remy,

That is very helpful.
So am I right in thinking that when writing to the ini file, UpdateFile() must
be called before deleting the TMemIniFile instance, or is this done automatically
by the deleting process?

David
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: Problem with TIniFile [Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 3, 2015 11:06 AM   in response to: David Ayre in response to: David Ayre
David wrote:

So am I right in thinking that when writing to the ini file,
UpdateFile() must be called before deleting the TMemIniFile
instance, or is this done automatically by the deleting process?

You must call UpdateFile() before destroying a TMemIniFile object. The TIniFile
destructor calls UpdateFile(), but the TMemIniFile destructor does not.

--
Remy Lebeau (TeamB)
David Ayre

Posts: 34
Registered: 10/11/00
Re: Problem with TIniFile [Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 4, 2015 1:55 AM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
You must call UpdateFile() before destroying a TMemIniFile object. The TIniFile
destructor calls UpdateFile(), but the TMemIniFile destructor does not.

Thanks Remy,

I will use that in future.

David
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02