RaiseEvent does not fire event


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 6 of 6

Thread: RaiseEvent does not fire event

  1. #1
    Mark Burns Guest

    RaiseEvent does not fire event

    VB6 question/problem:
    Is it legal to fire a class's events from within its own _Initialize procedure?
    If not - why does it fail silently rather than generate an error (which would at least be
    useful).

    I was trying to use events to simulate a parameterized constructor in VB6 to pass a
    parameter to a SQL query in a data class.
    Assuming that this will not fly, anybody want to recommend a workaround strategy?

    Code Example:

    ===class1.cls===
    Public Event Initializing()

    Private Sub Class_Initialize()
    <snip>
    RaiseEvent Initializing <==== event does not fire
    <snip>
    end sub
    ===maincode.cls===
    Private WithEvents CLS1 As class1

    public sub startup()
    set CLS1 = new class1
    end sub

    private sub CLS1_Initializing
    msgbox "Hi!"
    end sub
    ====mainmod.bas
    sub Main()
    dim MC as maincode

    set MC = new maincode
    mc.startup
    end sub
    =====end of example




  2. #2
    Anthony Jones Guest

    Re: RaiseEvent does not fire event

    >>
    Is it legal to fire a class's events from within its own _Initialize
    procedure?
    If not - why does it fail silently rather than generate an error (which
    would at least be
    useful).
    <<

    Yes it is legal that is why you do not get an error. There is no error not
    even a silent one.

    The event model allows for _Zero_ or more listeners for events. At the time
    of Class_Initialise the variable to which the new instance is to be assigned
    has not received the reference yet.

    --
    Anthony Jones
    Nuesoft Ltd



  3. #3
    Mark Burns Guest

    Re: RaiseEvent does not fire event


    "Anthony Jones" <anthony.jones@nonuesoft.spamco.uk> wrote in message
    news:3c728b89@10.1.10.29...
    > >>

    > Is it legal to fire a class's events from within its own _Initialize
    > procedure?
    > If not - why does it fail silently rather than generate an error (which
    > would at least be
    > useful).
    > <<
    >
    > Yes it is legal that is why you do not get an error. There is no error not
    > even a silent one.
    >
    > The event model allows for _Zero_ or more listeners for events. At the time
    > of Class_Initialise the variable to which the new instance is to be assigned
    > has not received the reference yet.


    Ah. yes. That'd explain it. Doh!
    <realizes his caffeine system must have to much blood in it again...goes to refresh his
    beverage>




  4. #4
    Michael Culley Guest

    Re: RaiseEvent does not fire event

    You can fake constructor by making a function in a module call (something
    like) NewClass1 which returns a new instance of Class1. So instead of set
    x=New Class1 you get set x=NewClass1(Params). Not exactly 100% but something
    like it. If the class is in a dll you can make it public not createable so
    that this function has to be used (obviously in this case it will have to go
    in a gmu class)

    "Mark Burns" <mburns@quixnet.net> wrote in message
    news:3c728e18$1@10.1.10.29...
    >
    > "Anthony Jones" <anthony.jones@nonuesoft.spamco.uk> wrote in message
    > news:3c728b89@10.1.10.29...
    > > >>

    > > Is it legal to fire a class's events from within its own _Initialize
    > > procedure?
    > > If not - why does it fail silently rather than generate an error (which
    > > would at least be
    > > useful).
    > > <<
    > >
    > > Yes it is legal that is why you do not get an error. There is no error

    not
    > > even a silent one.
    > >
    > > The event model allows for _Zero_ or more listeners for events. At the

    time
    > > of Class_Initialise the variable to which the new instance is to be

    assigned
    > > has not received the reference yet.

    >
    > Ah. yes. That'd explain it. Doh!
    > <realizes his caffeine system must have to much blood in it again...goes

    to refresh his
    > beverage>
    >
    >
    >




  5. #5
    Anthony Jones Guest

    Re: RaiseEvent does not fire event

    Michael,

    Umm... I fail to see how this helps. Raising an event during Initialize
    will _Never_ go anywhere.

    --
    Anthony Jones
    Nuesoft Ltd



  6. #6
    Mark Burns Guest

    Re: RaiseEvent does not fire event


    "Anthony Jones" <anthony.jones@nonuesoft.spamco.uk> wrote in message
    news:3c7371bf@10.1.10.29...
    > Michael,
    >
    > Umm... I fail to see how this helps. Raising an event during Initialize
    > will _Never_ go anywhere.


    Yes. You are right.
    What Michael was offering me was a way to get what I was after to begin with - a
    parameterized constructor.



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center