?
Solved

Long search - program 'hang up"

Posted on 2000-03-01
7
Medium Priority
?
126 Views
Last Modified: 2010-04-04
Hi everyone! Could you help me?

My program make a long search process and at this time my program doesn't respond on mouse clicks or another activities! even the form doesn't repaint if my program was closed by another program.
How should I change or add to my code that my program make this search and respond to my activities (for examle if I need to stop search process)
Please give me the exact instruction.
0
Comment
Question by:Masonok
[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
7 Comments
 
LVL 10

Expert Comment

by:Lischke
ID: 2571880
This is usually quite easy to do. If you have a loop where your application is waiting for a result then simply include:

  while ResultIsNotHere do
  begin
    :
    :
    Application.ProcessMessages;
  end;

in this loop. If you are waiting in an API call then it becomes a bit more complex as you need to use a separate thread.

Do you need the thread code too?

Ciao, Mike
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 2571884
hi masonok,

just place
application.processmessages
sometimes in your searchroutine

to stop search
place a button,
which sets a var,
which you check in your searchroutine

meikl
0
 
LVL 10

Expert Comment

by:Lischke
ID: 2571908
Hi Meikl :-)

have you seen that we are answering so fast that the answer came one day before the question ;-))

Ciao, Mike
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 27

Expert Comment

by:kretzschmar
ID: 2571911
:-))
yup, faster than the time (overlightspeed)
0
 

Author Comment

by:Masonok
ID: 2571914
Good idea!
Could you help me with threads, please?
0
 
LVL 10

Accepted Solution

by:
Lischke earned 400 total points
ID: 2571954
Well, then write an own TThread descentant to override the Execute method:

type
  TSearchThread = class(TThread)
  public
    procedure Execute; override;
  end;

and create this thread whenever you need to search. The thread's execute method contains the code to do the actual search:

procedure TSearchThread.Execute;

begin
  while not Terminated do
  begin
    // do your search stuff here
  end;
end;


The form could create the thread with a button click handler:

procedure TForm1.Button1Click(Sender: TObject);

begin
  if FSearching then
  begin
    FSearchThread.Terminate;
    FSearchThread.WaitFor;
  end;
  FSearching := True;
  // create the thread suspended to prepare it a bit before the search can be started
  FSearchThread := TSearchThread.Create(True);
  FSearchThread.FreeOnTerminate := True;
  FSearchThread.OnTerminate := OnTerminate; // in this event set FSearching to False
  // further data needed in the thread should be assigned here
  FSearchThread.... := ...
  // now start the thread
  FSearchThread.Resume;
end;

After the thread has been created the application will run as if there was nothing happend and can respond to other events.

Ciao, Mike
0
 

Author Comment

by:Masonok
ID: 2571971
Thanks!
0

Featured Post

Technology Partners: 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

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…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses
Course of the Month8 days, 10 hours left to enroll

764 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