运行时包中的 Delphi TDataSet

发布于 2024-09-30 02:22:59 字数 529 浏览 0 评论 0原文

我正在创建一个运行时包,其中包含我的主应用程序可以使用的类,但我在数据访问方面遇到问题。 我的主应用程序包含一个指向 BDE 别名的 TDatabase。在运行时,我的包被动态加载,并且在包中调用一个方法,该方法创建一个 TQuery 并打开它,用返回的数据填充一个对象,然后将该对象返回到主应用程序。 TQuery 使用主应用程序中的 TDatabase 连接到数据库。 所有这些工作正常,但当我关闭应用程序时,我收到访问冲突:“项目 C:...GUI.exe 出现错误,并显示消息“访问冲突位于 0x7c9102db:写入地址 0x00040ffc”。进程已停止。使用 Step 或 Run 来继续”。 如果我的方法创建了 TQuery 但没有打开它,则不会发生此错误。我不知道为什么会发生这种情况!当我关闭应用程序时,我的 TQuery 已关闭并释放,我的包已卸载,但在表单被销毁后​​,出现错误。 顺便说一句,我正在使用 Delphi 5,我尽量简短,所以如果我错过了任何有用的信息,请告诉我,任何帮助都会感激不尽。

谢谢

​我知道使用 Delphi 5 和 BDE 已经过时了,但我现在还是坚持使用它!

I am creating a runtime package which contains classes that my main application can use, but I'm having problems with the data access.
My main app contains a TDatabase which points to a BDE alias. At runtime my package is dynamically loaded, and a method invoked in the package which creates a TQuery and opens it, populates an object with the returned data and then returns the object to the main app. The TQuery uses the TDatabase in the main app to connect to the database.
All this works fine, but when I close the app I get an access violation: "Project C:...GUI.exe faulted with message 'access violation at 0x7c9102db: write of address 0x00040ffc'. Process Stopped. Use Step or Run to continue".
If my method creates the TQuery but doesn't open it then this error does not occur. I have no idea why this happens! When I close th app my TQuery is closed and freed ok, my package is unloaded ok, but after the form is destroyed the error occurs.
I'm using Delphi 5 BTW, I've tried to be brief so if I have missed out any helpful info let me know, any help gratefully received.

Thanks

p.s. I know that using Delphi 5 and BDE is archaic but I'm stuck with it for now!

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

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

发布评论

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

评论(3

夏末 2024-10-07 02:22:59

如果您不释放 TQuery 怎么办?我的意思是,当应用程序终止时,尽量不要释放 TQuery 对象。

What if you don't free your TQuery? I mean, try not to free your TQuery object when application terminates.

生生漫 2024-10-07 02:22:59

我使用 dbExpress 时发生过这种情况,当应用程序被 Abort()ed 时,终结部分会在数据模块析构函数之前触发,这会引起很多头痛。

因此,我的猜测是

  • BDE 的连接驱动程序(或其他一些资源)在使用它的东西被破坏之前完成,因此尝试两次完成连接。

我说驱动程序是因为它们通常只按需加载/初始化,因此如果不使用它也不会出错。因此,也许当您的软件包被卸载时,它就会完成驱动程序。

尝试这样做:

  • 加载您的包,
  • 使用包中包含的 TQuery,
  • 卸载您的包,
  • 使用主应用程序中创建的另一个 TQuery,

然后看看这是否可以正常工作而不会引发异常。如果它不起作用,那么我想我可能是对的,我们将尝试找出如何使其起作用。

上帝保佑!

This happened with me using dbExpress, the finalization section would fire before a datamodule destructor, when application was Abort()ed and that caused a lot of head ache.

So, my guess would be that

  • BDE's connection driver (or some other resource) is finalizing before the destruction of something that uses it, therefore attempting to finalize the connection twice.

I say driver because those are usually only loaded/initialized on demand, thus it wouldn't fault if it wasn't used. So, maybe when your package is unloaded it finalizes the drivers.

Try this:

  • load your package,
  • use the TQuery contained in the package,
  • unload your package,
  • use another TQuery created in the main application,

and see if this works without raising exceptions. If it doesn't work then I guess I could be right, and we'll try to figure out how to make this work.

God bless!

美人如玉 2024-10-07 02:22:59

听起来像是单元初始化/完成顺序问题。通常,这取决于使用列表中的单元顺序以及您的包需要哪些包。

尝试解决此问题的最佳方法是使用 Delphi 调试 Delphi,或使用 .EXE 调试包。
最后一项很重要,因为如果您开始使用 EXE 进行调试,旧的 Delphi 版本并不总能找到您的包的符号。

步骤

  1. 启动不包含您的包的 Delphi
  2. 在 Delphi 中加载您的包
  3. 将您的包的主机设置为 Delphi
  4. 使用完整的调试信息编译您的包,并启用选项“调试 DCU”
  5. 运行您的包(它现在应该加载 Delphi,然后是你的包)
  6. 终止 Delphi
  7. 在 AV 发生时观察调用堆栈

您可能需要设置断点来观察初始化/最终化顺序(请参阅 这篇文章,对此进行讨论的参考文献和评论)。

然后摆弄您的使用列表和包要求部分。

——杰罗恩

Sounds like a unit initialization/finalization order issue. Usually that is determined by the order of units in the uses lists, and what packages your package requires.

Best way to try to solve it is to debug Delphi with Delphi, or your package with a .EXE.
The last one is important, because older Delphi versions won't always find the symbols for your package if you start debugging with your EXE.

Steps

  1. Start a Delphi that does not contain your package
  2. Load your package in Delphi
  3. Set the host of your package to be Delphi
  4. Compile your package with full debug information, and enable the option 'debug DCU's'
  5. Run your package (it should now load Delphi, then your package)
  6. Terminate Delphi
  7. Watch the call stack when the AV occurrs

You might want to set breakpoints to watch your initialization/finalization order (see this post, the references and the comments for a discussion on that).

Then fiddle with your uses lists and package requirements sections.

--jeroen

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