Solved

Long search - program 'hang up"

Posted on 2000-03-01
7
125 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 100 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

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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …

695 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