运行时包中的 Delphi TDataSet
我正在创建一个运行时包,其中包含我的主应用程序可以使用的类,但我在数据访问方面遇到问题。 我的主应用程序包含一个指向 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您不释放 TQuery 怎么办?我的意思是,当应用程序终止时,尽量不要释放 TQuery 对象。
What if you don't free your TQuery? I mean, try not to free your TQuery object when application terminates.
我使用 dbExpress 时发生过这种情况,当应用程序被
Abort()
ed 时,终结部分会在数据模块析构函数之前触发,这会引起很多头痛。因此,我的猜测是
我说驱动程序是因为它们通常只按需加载/初始化,因此如果不使用它也不会出错。因此,也许当您的软件包被卸载时,它就会完成驱动程序。
尝试这样做:
然后看看这是否可以正常工作而不会引发异常。如果它不起作用,那么我想我可能是对的,我们将尝试找出如何使其起作用。
上帝保佑!
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
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:
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!
听起来像是单元初始化/完成顺序问题。通常,这取决于使用列表中的单元顺序以及您的包需要哪些包。
尝试解决此问题的最佳方法是使用 Delphi 调试 Delphi,或使用 .EXE 调试包。
最后一项很重要,因为如果您开始使用 EXE 进行调试,旧的 Delphi 版本并不总能找到您的包的符号。
步骤
您可能需要设置断点来观察初始化/最终化顺序(请参阅 这篇文章,对此进行讨论的参考文献和评论)。
然后摆弄您的使用列表和包要求部分。
——杰罗恩
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
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