开发者

Crystal Reports - Is TCrpe for Delphi threadsafe?

开发者 https://www.devze.com 2023-02-16 08:39 出处:网络
Short: Is it ok to execute the TCrpe component from within a non-VCL main thread? Long: I use the TCrpe component to create reports for Crystal Reports.

Short: Is it ok to execute the TCrpe component from within a non-VCL main thread?

Long: I use the TCrpe component to create reports for Crystal Reports. Until now I used the component within the VCL main thread and everything was fine.

But now I moved the component into a background thread. There is only 1 instance of the component at a time, and it is only accessed by one single thr开发者_StackOverflow社区ead, which is not the VCL main thread.

On my test environment everything seems to be fine. But on the production environment the application crashes from time to time: Access violations; Invalid Pointer operations; List index out of bound exceptions. The exceptions can occur almost anywhere, and not always I get an exception stacktrace.

So: Is it ok to execute the TCrpe component from within a non-VCL main thread?

I looked at the source code, and some GUI related things are used there, which make me doubt. They even call

while not PrintEnded do Application.HandleMessage;

from there. Actually this code path is not activated due to my report settings; however, it makes me wonder whether the TCrpe component is inteded for usage in background threads at all.

Also, for some reports the TCrpe component shows an own form for the user to enter additional report parameters. Is this an indicator that they are messing up the main message event loop? Or could it be that they are using an own message queue for that form?


If this component shows any forms then it is using VCL components. All use of the VCL in an application must be done in the same thread, it's a requirement of the VCL.

You need to find a design that runs all the VCL code in the main application thread.

Having said all that, this doesn't explain why you see crashes only away from the test environment. The advice about threading is valid, but you most probably have a different problem.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号