Solved

INI files

Posted on 2002-04-02
8
236 Views
Last Modified: 2010-04-04
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(ListBoxFiles.Items.Strings[jw3]);
     StatusBar1.Panels[1].Text:='changing : '+ListBoxFiles.Items.Strings[jw3];
     StatusBar1.Panels[0].Text:=inttostr(jw3+1) + '/' + inttostr(antal);

  if form1.Edit1.Text <> '' then
  begin
    IniFile.WriteString(form1.Edit1.Text,form1.Edit2.Text,form1.Edit3.Text);
  jw33:='ja';
  end;

………….
0
Comment
Question by:Dark_King
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 11

Expert Comment

by:robert_marquardt
ID: 6912984
Do you ever destroy the IniFile object you created?
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.
0
 
LVL 3

Expert Comment

by:SteveWaite
ID: 6913162
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(ThreadException);
 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.
0
 
LVL 6

Author Comment

by:Dark_King
ID: 6924819
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..  
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 11

Expert Comment

by:robert_marquardt
ID: 6924894
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.
0
 
LVL 7

Expert Comment

by:God_Ares
ID: 6936574
could you post cour ini code here?
0
 
LVL 3

Accepted Solution

by:
SteveWaite earned 300 total points
ID: 6938060
Here's a thread example that does not pause your gui user i/f and does not use up 100% cpu time:

type
  TMyThread = class(TThread)
  private
    { Private declarations }
    FCount: Integer;
  protected
    { Protected declarations }
    procedure DoWork;
    procedure ThreadException;
    procedure Execute; override;
  public
    { Public declarations }
    constructor Create;
  end;

  TForm1 = class(TForm)
   //etc.
  end;

var
  Form1: TForm1;
  AThread: TMyThread;

implementation

{$R *.DFM}

{TMyThread}

constructor TMyThread.Create;
begin
  inherited Create(True); // i.e. Create Suspended
  FreeOnTerminate := False;
  FCount := 0;
end;

procedure TMyThread.Execute;
begin
  while not Terminated do
  try
    DoWork;
    Sleep(1000); // here's where you sleep!
  except
    if not (ExceptObject is EAbort)
      then Synchronize(ThreadException);
  end;
end;

procedure TMyThread.DoWork;
begin
  Inc(FCount);
  if FCount > 10 then
  begin
    FCount := 0;
  end;
end;

procedure TMyThread.ThreadException;
begin
  raise Exception.Create('thread problem');
end;

{TForm1}

procedure TForm1.FormCreate(Sender: TObject);
begin
  AThread := TMyThread.Create;
  AThread.Resume;
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  AThread.Free;
end;

try this out..
0
 
LVL 6

Author Comment

by:Dark_King
ID: 6941224
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
0
 
LVL 3

Expert Comment

by:SteveWaite
ID: 6942123
Splendid!

Thanks,
Steve
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
code issue 8 188
select query - oracle 16 101
how to change, disabled button color FMX ? 1 51
enhance the following code 3 42
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question