How can I implement a message loop within a thread using OTL? Application.ProcessMessages; is what i used so far but it isn’t very safe to use it.
Thanks
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
This is how I pull messages off a thread’s queue:
Using
Application.ProcessMessageswill pull messages of the queue of the calling thread. But it’s not appropriate to use in a message loop because it won’t block. That’s why you useGetMessage. It blocks if the queue is empty. AndApplication.ProcessMessagesalso calls otherTApplicationmethods that are not designed to be thread safe. So there are plenty of reasons not to call it from a thread other than the main thread.When you need to terminate the thread, then I do this:
None of this is OTL specific. This code all is intended to live in a
TThreaddescendent. However, the ideas are transferable.In the comments you indicate that you want to run a busy, non-blocking message loop. You would use
PeekMessagefor that.