In Delphi, is TDataSet thread safe?

前端 未结 6 1326
没有蜡笔的小新
没有蜡笔的小新 2021-01-02 02:30

I\'d like to be able to open a TDataSet asynchronously in its own thread so that the main VCL thread can continue until that\'s done, and then have the main VCL thread read

6条回答
  •  执念已碎
    2021-01-02 03:08

    I've done multithreaded data access, and it's not straightforward:

    1) You need to create a session per thread.

    2) Everything done to that TDataSet instance must be done in context of the thread where it was created. That's not easy if you wanted to place e.g. a db grid on top of it.

    3) If you want to let e.g. main thread play with your data, the straight-forward solution is to move it into a separate container of some kind,e.g. a Memory dataset.

    4) You need some kind of signaling mechanism to notify main thread once your data retrieval is complete.

    ...and exception handling isn't straightforward, either...

    But: Once you've succeeded, the application will be really elegant !

提交回复
热议问题