0

I have a TClientDataSet connected to some controls via LiveBindings. Assuming that:

  • no concurrent accesses to dataset is made
  • all controls are "hidden" (not disabled)

Can I update the dataset from a background thread?

If this is not safe, would be ok to set Active = false all binding links while updating the dataset? Finally, is there a centralized way to enable/disable all binding links? (something like EnableControls/DisableControls for datasets)

Begin Edit

This is not a question about TClientDataSet thread-safety, but rather a question about accessing a dataset from outside VCL thread (which is also safe if there are no concurrent access also from VCL thread) while there are active LiveBindings connections to some controls.

In this other question about thread-safe TClientDataSet access there are no info about LiveBindings and non-VCL thread access.

End Edit

(Environment: C++ Builder 10.3 or 10.4, VCL based application) Thanks, Alex B.

Alex B.
  • 43
  • 1
  • 5
  • I edited the question as the provided solution (duplicate) does not point the real subject of the question, which is LiveBindings. I would like eventually to have a link to the reference documentation that clears the questions. – Alex B. Dec 04 '20 at 08:25
  • As I understand the linked duplicate question, you cannot update a dataset from another thread. You can only read it. So the answer of your question "Can I update the dataset from a background thread?" is "No, you can't". – fpiette Dec 04 '20 at 10:06
  • Datasets can be accessed from any thread as long as no concurrent access is – Alex B. Dec 04 '20 at 13:40
  • Sorry hit enter too soon.. @fpiette thanks, there must be some misunderstanding here due to my poor explains. When I say "background thread" I mean a non-VCL thread (say worker thread) that exclusively access the TClientDataSet to either read or write data to and from it. From my understanding this is perfectly legal. What is not really clear is what happens if the dataset is also connected with "livebindings". – Alex B. Dec 04 '20 at 14:21
  • Anyway, after googling around some more and with some direct testing I understand that the answer is anyway "No, you cannot update the dataset from a non-VCL thread, if there are LiveBindings on it. The reason may be that LiveBindings are bound to VCL(GUI) thread. This means that while the worker thread is accessing the dataset, there could be a concurrent not access from another thread (VCL). The only solution here is to "disable" livebinding links as mentioned above. I will post anyway a separated question for the other request. Thanks – Alex B. Dec 04 '20 at 14:40
  • @AlexB. Yes, that's correct. There is no way to enforce an exclusive write lock on a data set that has bindings to VCL controls. Naturally, you can enforce exclusive access if it does not have said bindings. – J... Dec 04 '20 at 17:29

0 Answers0