- 性别
- 保密
- 积分
- 315
- 积分
- 1179
- 精华
- 2
- 阅读权限
- 200
- 注册时间
- 2012-8-1
- 最后登录
- 2013-11-20
- 帖子
- 264
- 性别
- 保密
|
作者:Kill 日期:2013-10-13 原文地址:http://www.skywj.com/thread-9189-1-1.html
好几年前的一个自己用VB写的一个记事本程序,今天偶然看到一篇好文章,想把它收藏进去,之前一直运行得好好的程序突然报错:
Procedure declaration does not match description of event or procedure having the same name
意思是“过程声明与过程描述不匹配或者过程重名”,于是到源程序中查看,问题出在事件上:
Private Sub Adodc1_MoveComplete(ByVal adReason As ADODB.EventReasonEnum, ByVal pError As ADODB.Error, adStatus As ADODB.EventStatusEnum, ByVal pRecordset As ADODB.Recordset)
引发错误的是最后一个参数:ByVal pRecordset As ADODB.Recordset
可是这个声明是向导添加的,而且一直运行良好。
不过我们知道,微软件的数据库中存在着不少至今也没能很好解决的问题。网上查了下,有关于这个错误的中文资料基本没有,然后在微软件MSDN上的找到一篇说明:
In versions of Visual Basic 6 prior to Service Pack 4, the ADO Data Control's events were designed to work only with ADO version 2.0. After you set a Reference to ADO later than 2.0 to workaround the Application Wizard problem, you receive the following error message
Compile Error: Procedure declaration does not match description of event or procedure having the same name.
To work around this new compile error, you must change the declaration of the ADO Data Control's events to include ADODB.Recordset20 instead of ADODB.Recordset.
Specifically, change the following event procedure:
Private Sub datPrimaryRS_MoveComplete(ByVal adReason As ADODB.EventReasonEnum, ByVal pError As ADODB.Error, adStatus As ADODB.EventStatusEnum, ByVal pRecordset As ADODB.Recordset)
-to-
Private Sub datPrimaryRS_MoveComplete(ByVal adReason As ADODB.EventReasonEnum, ByVal pError As ADODB.Error, adStatus As ADODB.EventStatusEnum, ByVal pRecordset As ADODB.Recordset20)
这段意思是说:VB6.0 SP4以前的版本,ADODC控件的事件在设计上是和ADO版本2.0匹配的,如果添加的参考是2.0以后的,就会出现这个错误。要解决这个错误可以把声明:
Private Sub datPrimaryRS_MoveComplete(ByVal adReason As ADODB.EventReasonEnum, ByVal pError As ADODB.Error, adStatus As ADODB.EventStatusEnum, ByVal pRecordset As ADODB.Recordset)
改成:
Private Sub datPrimaryRS_MoveComplete(ByVal adReason As ADODB.EventReasonEnum, ByVal pError As ADODB.Error, adStatus As ADODB.EventStatusEnum, ByVal pRecordset As ADODB.Recordset20)
我用2种方法尝试了
1、把参考改成ADO2.0的
2、参考用2.0以后的,声明改成ADODB.Recordset20
仍然不能解决问题,因为我的已经是SP6,而现在Win7里的ADO版本已经到2.8了。继续找资料,找到一个英文贴子:
I found a solution or work around
========================
1- I declared in my form
Option Explicit
Dim WithEvents db As ADODB.Recordset
2- then so that the form reseives event from Adodc I did this
Private Sub Form_Load()
Set db = Adodc1.Recordset
End Sub
Now when i select db in forms object i can see the events and they are generated automatic
Private Sub db_MoveComplete(ByVal adReason As ADODB.EventReasonEnum,
ByVal pError As ADODB.Error, adStatus As ADODB.EventStatusEnum, ByVal pRecordset As ADODB.Recordset)
MsgBox "It works"
End Sub
========================
我把这段主要意思翻译下:
1、先在窗体加上声明:
Option Explicit
Dim WithEvents db As ADODB.Recordset
2、在主窗体Load事件中加上
Private Sub Form_Load()
Set db = Adodc1.Recordset
End Sub
3、更改ADODC的事件声明为
Private Sub db_MoveComplete(ByVal adReason As ADODB.EventReasonEnum,
ByVal pError As ADODB.Error, adStatus As ADODB.EventStatusEnum, ByVal pRecordset As ADODB.Recordset)
也就是把Adodc1改成了db,按照上面的步骤修改,问题彻底解决,一切恢复正常,我的记事本也可以正常运行了:
|
|