Crystal Reports - Delphi 的 TCrpe 线程安全吗?

发布于 2024-10-21 17:14:27 字数 628 浏览 2 评论 0原文

简短:可以在非 VCL 主线程中执行 TCrpe 组件吗?

:我使用 TCrpe 组件为 Crystal Reports 创建报告。 到目前为止,我在 VCL 主线程中使用该组件,一切都很好。

但现在我将该组件移动到后台线程中。组件一次只有 1 个实例,并且只能由一个线程访问,该线程不是 VCL 主线程。

在我的测试环境中一切似乎都很好。 但在生产环境中应用程序时不时崩溃:访问冲突;无效的指针操作;列出索引越界异常。异常几乎可以发生在任何地方,并且并不总是我得到异常堆栈跟踪。

那么:可以从非 VCL 主线程中执行 TCrpe 组件吗?

我查看了源代码,里面使用了一些与GUI相关的东西,这让我产生疑问。他们甚至

while not PrintEnded do Application.HandleMessage;

从那里打电话。实际上,由于我的报告设置,该代码路径并未激活;然而,这让我想知道 TCrpe 组件是否适合在后台线程中使用。

此外,对于某些报告,TCrpe 组件会显示自己的表单,供用户输入其他报告参数。这是否表明他们正在搞乱主消息事件循环?或者他们可能正在为该表单使用自己的消息队列?

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 thread, 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

短叹 2024-10-28 17:14:27

如果该组件显示任何形式,那么它正在使用 VCL 组件。应用程序中对 VCL 的所有使用都必须在同一个线程中完成,这是 VCL 的要求。

您需要找到一个在主应用程序线程中运行所有 VCL 代码的设计。

话虽如此,这并不能解释为什么您只在远离测试环境的地方看到崩溃。关于线程的建议是有效的,但您很可能遇到不同的问题。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文