Microsoft KB Archive/217026

= PRB: IPF from UserControl with a User-Defined Validate Event =

Article ID: 217026

Article Last Modified on 5/12/2003

-

APPLIES TO


 * Microsoft Visual Basic 6.0 Learning Edition
 * Microsoft Visual Basic 6.0 Professional Edition
 * Microsoft Visual Basic 6.0 Enterprise Edition

-



This article was previously published under Q217026



SYMPTOMS
You have a control that contains: event Validate(Cancel as Boolean) event Change You get an Invalid Page Fault (IPF) when the control fires the Change event.



CAUSE
When you put a control on the Visual Basic form, Visual Basic creates an extended control that provides some extended properties. The extended control has several events reserved, such as: event DragDrop(Source As Control, X As Single, Y As Single) event DragOver(Source As Control, X As Single, Y As Single, State As Integer) event GotFocus event LostFocus event Validate(Cancel As Boolean) When a Visual Basic client tries to sink an event, the extended control's events and the control's events will be combined into the same vtable. However, if your control also defines a Validate event, Visual Basic cannot distinguish between them and considers them to be one, so that the vtable structure for the sink is incorrect.

Furthermore, if you define other events used in the extended control, you may get an error message when you try to load the control to your project. A typical error message would be: "xxx control could not be loaded."



RESOLUTION
Change the Validate event to another name, such as: event ValidateData(Cancel as Boolean) You can also use the same event name with a different argument list, but then you cannot get to the event entry from the combo box in the integrated development environment (IDE).



Steps to Reproduce Behavior
 Create a new ActiveX control project in Visual Basic. Change the project name to "MyOCX". Add a CommandButton to the usercontrol.  Add the following code to the code window of the usercontrol: Option Explicit Event Validate(Cancel As Boolean) Event Change

Private Sub Command1_Click RaiseEvent Change End Sub  Compile the project, and it will be registered automatically. Close this project. Create a new Standard EXE project. Form1 is created by default. From the Project menu, select Components, select MyOCX from the list, and click OK. MyOCX is now available in the Toolbox.</li> Add a MyOCX control to Form1.</li>  Add the following code to the code window of Form1. Option Explicit

Private Sub UserControl11_Change MsgBox "OK" End Sub </li> Press the F5 key to run the project. Click CommandButton and you get an IPF.</li></ol>

Additional query words: GPF

Keywords: kbprb kbactivexevents KB217026

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.