Solved

Long search - program 'hang up"

Posted on 2000-03-01
7
123 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
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!

 
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: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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

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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
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…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

762 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