0

我有一个与一些共享 TADOConnection 的 TDataModules 的库。我在某些应用程序中创建和删除数据模块。

当我删除数据模块时,我收到 EAccessViolation 错误。我认为这是因为数据模块想要删除共享的 TADOConnection。

我尝试在调用析构函数时将 tdatamodule->tbquery->Connection 属性设置为 NULL,但没有任何运气。

为什么我认为错误存在于 TADOConnection 中?因为当我在没有库的情况下构建应用程序时,我可以毫无问题地创建和删除数据模块。当我使用具有自己连接的数据模块创建一个库时,我也没有问题。

有什么帮助吗?提前致谢!

错误: http: //oi60.tinypic.com/noyc6x.jpg

调用栈: http: //oi61.tinypic.com/sgljx5.jpg

4

2 回答 2

0

TDataModule唯一释放它拥有的东西。TADOConnection如果您在多个实例中共享一个,TDataModule那么他们不能都拥有它。但是,也许您正在释放 Owner 而没有通知其他实例TADOConnection正在释放。VCL 有一个为此目的的机制——TComponent::FreeNotification()方法。您的TDataModule对象可以覆盖虚拟方法,Notification()然后调用FreeNotification(). TADOConnection这样,如果TADOConnection被释放,任何TDataModule正在使用它的人都可以采取相应的行动,例如将他们的本地指针设置为 NULL,这样他们就知道它TADOConnection已经消失了。

于 2014-01-31T17:10:32.120 回答
0

解决方案是使用库或 dll 添加borlndmm.dll到应用程序的项目文件夹中。

来自 Borland C++ Builder 中的 dll/lib 项目:

//---------------------------------------------------------------------------
//   Important note about DLL memory management when your DLL uses the
//   static version of the RunTime Library:
//
//   If your DLL exports any functions that pass String objects (or structs/
//   classes containing nested Strings) as parameter or function results,
//   you will need to add the library MEMMGR.LIB to both the DLL project and
//   any other projects that use the DLL.  You will also need to use MEMMGR.LIB
//   if any other projects which use the DLL will be performing new or delete
//   operations on any non-TObject-derived classes which are exported from the
//   DLL. Adding MEMMGR.LIB to your project will change the DLL and its calling
//   EXE's to use the BORLNDMM.DLL as their memory manager.  In these cases,
//   the file BORLNDMM.DLL should be deployed along with your DLL.
//
//   To avoid using BORLNDMM.DLL, pass string information using "char *" or
//   ShortString parameters.
//
//   If your DLL uses the dynamic version of the RTL, you do not need to
//   explicitly add MEMMGR.LIB as this will be done implicitly for you
//---------------------------------------------------------------------------
于 2014-02-18T12:12:50.753 回答