I am using TIdHttpServer to process some commands the problem is that some commands are beeing lost my guess is that it’s from the fact that i am updating the vcl inside OnConnect.
How can i use the Synchronize method to safley update the VCL ?
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.
It’s easy enough, just call
TThread.Synchronize()with whateverTThreadMethodyou want to be called by the GUI thread.TThreadMethodis a parameterlessprocedure of object, but since the secondary thread making the call is blocked until after the synchronized method has been executed by the GUI thread, you can useTThreadmembers in the synchronized method without any further protection.Just for completenes, I should mention that there are several alternatives, all of which are better (even those I haven’t tried because nothing could be worse). Indy has
TIdSyncandTIdNotifyclasses that you can derive from to carry variables and implement custom methods. Newer Delphi versions haveTThread.Queue()andTThread.ForceQueue()that can use anonymous methods to generate closures (with captured variables) that can be executed by the GUI thread without blocking the calling thread. There is also thePostMessage()andPostThreadMessage()APIs – a comms system that has worked without change since D3/W95 and is sure to be available on Windows forever.