views:

603

answers:

4

Hi

I have a TClientDataset that is managed in Thread 1.

In a different thread I have a cloned Image of the TClientDataset.

Will I run into threading problems?

Edit

The cloned image is used in a read only mode.

+4  A: 

The clone process should be handled with a TCriticalSection, but each TClientDataSet should be fine in its own thread.

Tim Sullivan
+8  A: 

In a word: No.

All of the VCL should be considered "thread unsafe". Any calls to visual components in a TThread should be made in a Synchronize event.

Any VCL/RTL class should be created and destroyed entirely within a TThread.

Nick Hodges
+5  A: 

The short answer is no, a ClientDataSet is not thread safe. The more involved answer is that it depends on how you use it. No matter how many clones of the ClientDataSet you have, they are safe to use from multiple threads so long as you are only reading the data. This is true even if you are setting different ranges, current records, filters, and so forth.

And, though you did not ask about this, you can free any of the cloned ClientDataSets, even the original ClientDataSet that was cloned, without problems.

On the other hand, if there is any need to ever post a record to any of the clones, or reload the data, you must use a synchronization object. If the changes are rare, the TMultiReadExclusiveWriteSynchronizer class is great one to use for this purpose.

Cary Jensen
A: 

Is this also true for the non-visual component?

Diego