Solved

Long search - program 'hang up"

Posted on 2000-03-01
7
119 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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

759 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now