Delphi - Is TClientDataset Thread Safe?

后端 未结 3 626
情歌与酒
情歌与酒 2021-01-02 05:00

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?

3条回答
  •  感情败类
    2021-01-02 05:17

    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.

提交回复
热议问题