I want to design my TFDQuery
using the component editor, i.e. set the SQL string, options etc. during design-time and then use the query in a thread.
My problem is that each running instance of the thread needs its own instance of the query - otherwise it will not be thread-safe.
Should I clone the query when the thread starts running, i.e. in the Execute method of the thread, and then set its connection - if so, how? Or is there a better way to do this?
Thank You
As described in the documentation:
...after a thread opens a query and until its processing is finished, the application cannot use this query and the connection objects in another thread. Similarly, after a thread starts a transaction and until the transaction is finished, the application cannot use this transaction and the connection objects in another thread.
And also:
The standard simplification is to create and use for each thread a dedicated connection object working with the database.
So the easiest solution is to have a separate connection per worker thread. In case you use the FireDAC (connection, transaction and query) components all on the same datamodule then the easiest solution for you might be to simply create a separate instance of the whole datamodule for each of your worker threads.