Solved

event-handling routines are not called

Posted on 2001-06-18
8
167 Views
Last Modified: 2010-04-06
Hi!

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

actual_time:=timeGetTime;
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

Semaphore:=False
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
Martin
0
Comment
Question by:mdietz
  • 4
  • 2
  • 2
8 Comments
 
LVL 2

Expert Comment

by:FrodoBeggins
ID: 6202067
Use Application.ProcessMessages; in your loop
0
 
LVL 2

Expert Comment

by:FrodoBeggins
ID: 6202076
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.
0
 
LVL 2

Accepted Solution

by:
FrodoBeggins earned 100 total points
ID: 6202086
example:
procedure TfrmListRez.pmenuPorListClick(Sender:TObject);
begin
  if bFlag the exit;
  bFlag := true;
  repeat
    ...; // do something
    Application.ProcessMessages;
  until time_getTime>actual_time+t*1000;
  bFlag := false;
end;
0
 
LVL 1

Expert Comment

by:WiseGuy
ID: 6202402
Don't use a loop

Make Semaphore a property and in SetSemaphore react when the value is CHANGED to true
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 2

Author Comment

by:mdietz
ID: 6205418
Thanks, now it works fine.
0
 
LVL 1

Expert Comment

by:WiseGuy
ID: 6205453
The solution is a busy form of waiting. It WILL slow down your machine.
My solution wouldn't cause an extra overhead.

0
 
LVL 2

Expert Comment

by:FrodoBeggins
ID: 6205476
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.
0
 
LVL 2

Author Comment

by:mdietz
ID: 6205551
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.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
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…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
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…

705 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

12 Experts available now in Live!

Get 1:1 Help Now