VB6类有一个析构函数? [英] Does a VB6 class have a destructor?

查看:107
本文介绍了VB6类有一个析构函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我执行

 之类的语句时Set MyObject = Nothing 

在调用的类中有一个特定的函数(即我可以用作析构函数),做类似清理数组,断开数据库

类似 Class_Initialize ,构造函数,还有一个析构函数:

  Sub Class_Terminate 
...将析构函数代码放在这里
End Sub

此对象的引用计数达到零时执行此方法,引用此对象的变量已超出范围或已设置为其他值(例如 Nothing )。因此, Set MyObject = Nothing 只会调用析构函数,如果 MyObject 是引用此对象的最后一个变量。


When I execute a statement such as

Set MyObject = Nothing

is there a particular function inside the class that is invoked (i.e. that I can use as a destructor), to do things like clean up arrays, disconnect from databases, and so forth?

解决方案

Analogous to Class_Initialize, the constructor, there's also a destructor:

Sub Class_Terminate
    ... ' Put your destructor code here '
End Sub

This method is executed as soon as the reference count of this object reaches zero, i.e., when all variables that reference this object have gone out of scope or have been set to set to something else (e.g. Nothing). Thus, Set MyObject = Nothing will only call the destructor if MyObject is the last variable referencing this object.

这篇关于VB6类有一个析构函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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