Re:How Detect Keypress in a Non-Form Unit?
Quote
"Sheldon Shallon" <s...@ieee.org> wrote in message
news:3be71ecf.23807245@news.earthlink.net...
Quote
> My project has a unit containing procedures and functions used by some
> of the form units. One of the procedures has a long running time while
> one of the calling forms is on the screen. How can pressing of the
> Enter or Escape key be detected while the procedure is running?
> I have scattered Application.ProcessMessages statements in various
> places, but the form's OnKeypress event is not triggered by a
> keypress.
For this to make sense I believe your long running procedure must be
called from one of the event handlers associated with your form? In
that case the fact that your process is in a non-form unit should be
irrelevant because it is invoked under the applicable form.
If this handler should happen to be triggered by any kind of a keypress
activity I am very much in doubt if it will react to another keypress event
even if it suspends itself by a call to Application.ProcessMessages
I do not really know, but I would expect the events to be queued up
until the handler is ready for the next keypress event, and maybe this is
the
case even if the event that started the long running process was an event
even completely different from keypress.
I have a strong feeling that your problem is a typical case for
multithreading,
keep your VCL thread (with the form) free to process whatever keys or
mouse activities you may need and have a lower priority thread do the
processing. I have found
http://www.pergolesi.demon.co.uk/prog/threads/ToC.html
a very useful introduction to such programming - do take a look!
regards Sven