Afxdaoterm何时使用该术语 [英] Afxdaoterm when to use the term

查看:103
本文介绍了Afxdaoterm何时使用该术语的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有ocx,其中iam启动数据库并在该退出实例中我写了afxdaoint



函数在心室列表控件的构造函数中我已初始化数据库



和ocx存在的实例我调用了afxdaoterm但它的循环..我没有关闭exe access vialotion错误来了。



我尝试了什么:



如果我在存在的实例中使用AfxDaoTerm它没有关闭数据库它发生了什么可能递归是问题。

解决方案

AfxDaoTerm 没有关闭数据库。恰恰相反,它要求所有MFC DAO对象在调用之前已被销毁。因此,您不能使用DAO对象的实例,而是使用 new 分配它们并在调用 AfxDaoTerm 之前删除它们:

 CDaoDatabase * pDb = NULL; 

// 用于全局对象的InitInstance或本地对象的函数入口
pDb = CDaoDatabase;

// 用法
pDb-> Open() ;
// ...

// 在ExitInstance中用于全局对象或函数退出本地对象
if (pDb)
{
if (pDb-> IsOpen())
pDb->关闭();
delete pDb;
}

// ExitInstance
AfxDaoTerm( );


i have ocx in which iam initing the database and in that exit instance i wrote afxdaoint

function in the constructor of patricular list control i had init the database

and ocx exist instance i had called afxdaoterm but its looping ..i.e not closing the exe acces vialotion error came.

What I have tried:

if i used AfxDaoTerm in the exist instance its not closing the database its happening recursive what might be the problem.

解决方案

AfxDaoTerm is not closing the database. Quite the contrary it requires that all MFC DAO objects has been destroyed before calling it. Therefore you must not use instances of DAO objects but allocate them using new and delete them before calling AfxDaoTerm:

CDaoDatabase *pDb = NULL;

// In InitInstance for global objects or function entry for local objects
pDb = new CDaoDatabase;

// Usage
pDb->Open();
// ...

// In ExitInstance for global objects or function exit for local objects
if (pDb)
{
    if (pDb->IsOpen())
        pDb->Close();
    delete pDb;
}

// ExitInstance
AfxDaoTerm();


这篇关于Afxdaoterm何时使用该术语的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆