PRB: Event Does Not Fire in the IDE When Raised from Inside a Compiled Modal Form

ID: Q237286


The information in this article applies to:


SYMPTOMS

When using compiled components with events, and the event is triggered from a modal form inside the component, the event is not received by the client application when it is run from the Visual Basic Design Environment (IDE). This problem does not occur when both components have been compiled.


RESOLUTION

Display the form that triggers the event non-modally to avoid the problem when testing the application in the IDE.


STATUS

This behavior is by design.


MORE INFORMATION

Steps to Reproduce Behavior

  1. Start a new Visual Basic ActiveX DLL project. Class1 is created by default.


  2. On the Project menu, click Project1 Properties. In the Project Properties dialog box, set the Project Name field to MyEventsDll. Click OK.


  3. Add the following code to the General Declarations section of Class1:


  4. 
    Option Explicit
    
    Public Event DoSomething()
    
    Public Sub FireEvent()
        RaiseEvent DoSomething
    End Sub
    
    Public Sub ShowForm(ByVal ShowType As Long)
       Form1.SetEventObject Me
       If ShowType = vbModeless Then
          Form1.Caption = "Non-Modal"
          Form1.Show
       Else
          Form1.Caption = "Modal"
          Form1.Show vbModal
       End If
    End Sub 
  5. On the Project menu, click Add Form to add a new form to the project. Form1 is created by default.


  6. Add a CommandButton to Form1.


  7. Add the following code to the General Declarations section of Form1:


  8. 
    Option Explicit
    
    Dim EventObject As Class1
    
    Public Sub SetEventObject(objNew As Class1)
       Set EventObject = objNew
    End Sub
    
    Private Sub Command1_Click()
       EventObject.FireEvent
    End Sub
    
    Private Sub Form_Load()
       Command1.Caption = "Fire Event"
    End Sub 
  9. Save the project and compile it.


  10. On the File menu, click New Project. Create a new Visual Basic Standard EXE project. Form1 is created by default.


  11. Change the name of Form1 to frmTest.


  12. On the Project menu, click References. Add a reference by checking MyEventsDll and clicking OK.


  13. Add two CommandButtons to frmTest.


  14. Add the following code to the General Declarations section of frmTest:


  15. 
    Option Explicit
    
    Dim WithEvents MyObj As MyEventsDll.Class1
    
    Private Sub Command1_Click()
       MyObj.ShowForm vbModal ' Show Form Modal
    End Sub
    
    Private Sub Command2_Click()
       MyObj.ShowForm vbModeless ' Show Form Non-Modal
    End Sub
    
    Private Sub Form_Load()
       Set MyObj = New MyEventsDll.Class1
       Command1.Caption = "Show Form Modal"
       Command2.Caption = "Show Form Non-Modal"
    End Sub
    
    Private Sub MyObj_DoSomething()
       MsgBox "Received event from DLL"
    End Sub 
  16. Save the project.


  17. Press the F5 key to run the project in the IDE.


  18. Click the Show Form Non-Modal button to display the form from the DLL as non-modal. Click the Fire Event button. A message box displaying the text "Received event from DLL" should be displayed, confirming that the event fired from inside the DLL reached the client application.


  19. Close the non-modal form.


  20. Click the Show Form Modal button to display the form from the DLL as modal. Click the Fire Event button and observe that the message box is not displayed. This demonstrates that the event that was fired from the modal form was not received by the client.


  21. On the Project menu, click Make Project1.exe to compile the client.


  22. Run Project1.exe and repeat the steps above. The message box should display whether the form in the DLL is shown modally or non-modally.


Additional query words:


Keywords          : kbVBp kbVBp500 kbVBp600 kbIDEProject kbGrpVB kbDSupport 
Version           : WINDOWS:5.0,6.0
Platform          : WINDOWS 
Issue type        : kbprb 

Last Reviewed: August 12, 1999