event-handling routines are not called


I'm writing a program, that shows pictures for a user-defined time.  That works with

repeat until time_getTime>actual_time+t*1000;

So far everything is okay, but if the user enters -1 the picture should be shown until the user presses a key or clicks the mouse. I tried a similar approach with

repeat until Semaphore;

where Semaphore is a boolean that is set to True in one of two procedures that are connected to the onKeyPress and OnClick events of the component that shows the image. (The routines are connected to the corresponding events of the window as well as to the events of the Image-component.)

My problem is, that these two procedures are not called, and even if I use a special button-window I have to show it as ShowModal. It seems that the empty repeat-until-loop binds all the attention of the system and it has no time to react on the event.

How can I force the events to be handled, is there some other way to wait for an user-caused event like in good old Pascal the "repeat until keypressed"?

Oh, by the way, I'm using Borland Delphi 2.0

Thanks in Advance
Who is Participating?
procedure TfrmListRez.pmenuPorListClick(Sender:TObject);
  if bFlag the exit;
  bFlag := true;
    ...; // do something
  until time_getTime>actual_time+t*1000;
  bFlag := false;
Use Application.ProcessMessages; in your loop
But be careful - prevent event handler reentrancy. It occures when your loop is in an event handler, and the verry same event occures and takes place when you call the message pump.
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

Don't use a loop

Make Semaphore a property and in SetSemaphore react when the value is CHANGED to true
mdietzAuthor Commented:
Thanks, now it works fine.
The solution is a busy form of waiting. It WILL slow down your machine.
My solution wouldn't cause an extra overhead.

Well, WiseGuy, I can't see a big slowdown. Your solution relies in the message pump too - but indirectly. And you will  receive the messages later, then if you are in a loop waiting for them.
mdietzAuthor Commented:
To make it clear: After the PictureScreen.Show(); is called a routine WaitForSeconds(t:integer) is called. Inside this routine is the first time that the parameter t is interpreted, and after that routine the next picture is loaded. The interior of WaitForSeconds should not be cared about by the other procedures, and if I implement the Semaphore as an active element (which processes the List construct and loads the images) I would have to adapt the main procedure, and that would have great effect on the component structure.

 Anyway, there's nothing else to do for the computer while the image is shown, so why don't implement a busy waiting solution.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.