Wrox Home  
Search P2P Archive for: Go

  Return to Index  

pro_vb thread: RE: How to implement event sinks in VB on a componen t?


Message #1 by "Treize Krushrenada" <mrmagicis@h...> on Fri, 22 Mar 2002 22:12:29
So you have, I'm guessing you have 2 forms.  One with the main detail and 
the other with general detail.

-Form1
-Formx....

I hope you have a modMain or a basMain, that has a "sub main" in it.

-modMain

I have a modGlobal module in almost all my projects to hold the global 
vars.

-modGlobal

---------------------------
Okie, you'll want a single hook in to the object in "modGlobal"

"Public gobjMyCOMObject as MyCOMObject"

Now when you project loads, (hopefully you have the properties of the 
project run "Sub Main"), in "Sub Main" in your "modMain" you'll want to 
have you global hook to the object.  Then load the any Form, "Form1" or 2

"Sub Main()
  Set gobjMyCOMObject = New MyCOMObject
  Form1.show
 End Sub"

Now in the form you want to have an object withEvents. When the form load 
you'll want that object that supports withEvents to hook, to your global 
object.

"Option Explicit
 Private WithEvents mobjMyCOMObject as MyCOMObject 'Notice, it is PRIVATE

 Private Sub Form_Load()
   'Set the Modualar Object to the Global object
   'The Modualar Object Hooks to the Global, the Global to the COMObject
   Set mobjMyCOMObject = gobjMyCOMObject
 End Sub

 Private Sub Form_QueryUnload()
   'When the form closes clean up the Modular objects
   Set mobjMyCOMObject = Nothing
   'Remember, if this is the last closing form set the Global object
    'to nothing.
   'Set gobjMyCOMObject = Nothing
 End Sub"



> I'm also working from theory, but when you want to *use* an alternate
> interface, you've got to Dim a second variable as the alternate interface
> type, and then set the two vars equal to one another.  
> 
> Maybe that same approach will work for the events?  So for instance:
> 
> Dim WithEvents objFirst as clsFirstInterface
> Dim WithEvents objSecond as clsSecondInterface
> 
> Set objFirst = New clsFirstInterface
> Set objSecond = New clsSecondInterface
> 
> Set objSecond = objFirst
> 
> HTH,
> 
> -Roy
> 

  Return to Index