Following on from this thread, I am trying to make a C++Builder XE5 application with:
- a main form
- a
TIdTCPClient
- a
TThread
for thatTIdTCPClient
's connection, which opens the socket, sends a request, then listens for multiple responses indefinitely - actions that occur on the socket will cause updates on the main form
I have been unable to find any examples; the examples linked from the Indy Demos page all do not use any threads in their clients, so far as I can see.
My questions are:
- Should the TIdTCPClient be on the main form (as a design time component), or should it be a member variable of the thread class?
- In the events fired by the TIdTCPClient , does the code in the event handlers (which are member functions of my main form) need to be Synchronized?
- Is it safe for both the main VCL thread and the client thread to make function calls on the TIdTCPClient object?
Currently I take actions on the main form in response to every event, and also in response to receiving data on the socket. At the moment my code is full of temporary variables and stub functions because Synchronize
requires a void(void)
closure and it is quite spaghetti. So I wonder if I am taking a fundamentally wrong approach.