Dark_King
asked on
INI files
My program seek for INI files on server and use TiniFile to change in file..
It work great, but the server don’t like it.
It jumps from 5% to 60% on my Novell server and is not good.
I need to change 2000 ini files.
How should it be done.
Wait fore file to be ready or insert a timer do delay my program..
I try the timer but most be stupid, cant get it to work…try sleep and don’t like it..
AND my StatusBar is not update if I use timer or delay.. ??
Part of my code look like this, you can se where a need the delay..
for jw3:=0 to antal -1 do
begin
// Timer1.Interval:=2000;
// Timer1.Enabled:=True ;
// Sleep(500);
IniFile := TIniFile.Create(ListBoxFil es.Items.S trings[jw3 ]);
StatusBar1.Panels[1].Text: ='changing : '+ListBoxFiles.Items.Strin gs[jw3];
StatusBar1.Panels[0].Text: =inttostr( jw3+1) + '/' + inttostr(antal);
if form1.Edit1.Text <> '' then
begin
IniFile.WriteString(form1. Edit1.Text ,form1.Edi t2.Text,fo rm1.Edit3. Text);
jw33:='ja';
end;
………….
It work great, but the server don’t like it.
It jumps from 5% to 60% on my Novell server and is not good.
I need to change 2000 ini files.
How should it be done.
Wait fore file to be ready or insert a timer do delay my program..
I try the timer but most be stupid, cant get it to work…try sleep and don’t like it..
AND my StatusBar is not update if I use timer or delay.. ??
Part of my code look like this, you can se where a need the delay..
for jw3:=0 to antal -1 do
begin
// Timer1.Interval:=2000;
// Timer1.Enabled:=True ;
// Sleep(500);
IniFile := TIniFile.Create(ListBoxFil
StatusBar1.Panels[1].Text:
StatusBar1.Panels[0].Text:
if form1.Edit1.Text <> '' then
begin
IniFile.WriteString(form1.
jw33:='ja';
end;
………….
You should not call Sleep() in the gui thread. Put the work in another thread and call Sleep().
create a thread:
TMyThread=class(TThread)
constructor Create;
procedure Execute; override;
end;
Override the thread execute method and do an iteration of the work. only there do a Sleep().
In your thread execute method...
while (not Terminated) do // run indefinately
try
DoMyThing;
Sleep(FInterval);
if NoMoreIniFiles then Terminate; // or something..
except
if not (ExceptObject is EAbort)
then Synchronize(ThreadExceptio n);
end;
Choose the sleep value determined by how much you want this thread to take over the machine. The form
interacts smoothly with user.
Let me know if you need help with threads.
Regards,
Steve.
create a thread:
TMyThread=class(TThread)
constructor Create;
procedure Execute; override;
end;
Override the thread execute method and do an iteration of the work. only there do a Sleep().
In your thread execute method...
while (not Terminated) do // run indefinately
try
DoMyThing;
Sleep(FInterval);
if NoMoreIniFiles then Terminate; // or something..
except
if not (ExceptObject is EAbort)
then Synchronize(ThreadExceptio
end;
Choose the sleep value determined by how much you want this thread to take over the machine. The form
interacts smoothly with user.
Let me know if you need help with threads.
Regards,
Steve.
ASKER
SteveWaite.
Sorry for the delay, problem with Expert suite..
I not that good on Delphi, need more exact help to fix this..
It work with sleep the wrong way, but I can’t stop the procedure if I want.
I made a button to stop my procedure, but can’t hit the button..
Sleep is only there to make a delay before change ini files, server get to much to do else.
I want to try your example, but you have to explain more in detail..
Sorry for the delay, problem with Expert suite..
I not that good on Delphi, need more exact help to fix this..
It work with sleep the wrong way, but I can’t stop the procedure if I want.
I made a button to stop my procedure, but can’t hit the button..
Sleep is only there to make a delay before change ini files, server get to much to do else.
I want to try your example, but you have to explain more in detail..
Your button cannot work because you do not process the messages inside your loop.
Inside your loop you call TIniFile.Create which creates a new object.
You never call IniFile.Free in the loop so each newly created object is placed in IniFile and you lose track of the last object.
The lost object is not freed automatically so it still exists and it still has its file open.
You will end up with 1999 of 2000 open files which you cannot close.
Inside your loop you call TIniFile.Create which creates a new object.
You never call IniFile.Free in the loop so each newly created object is placed in IniFile and you lose track of the last object.
The lost object is not freed automatically so it still exists and it still has its file open.
You will end up with 1999 of 2000 open files which you cannot close.
could you post cour ini code here?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
HEHE,, 4 minutes to find all ini file, and under 2 minutes to fix the files..
BUT THE SERVER WAS NOT HAPPY, The delay fix this, Great help SteveWaite
BUT THE SERVER WAS NOT HAPPY, The delay fix this, Great help SteveWaite
Splendid!
Thanks,
Steve
Thanks,
Steve
From the code posted it seems that you create 2000 objects (which means 2000 open files) and you lose track of 1999 of the objects.
Add a IniFile.Free as last line of the loop.