Solved

Long search - program 'hang up"

Posted on 2000-03-01
7
122 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
  • 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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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…
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…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

840 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