Class raising an event from another class? 
Author Message
 Class raising an event from another class?

I have the following situation:

In a form (Form1), I want to create an instance of Class1
At some point, Class1 needs to execute raise an event in Form1.
Can this be done? How?

I posted this question a few days ago and Dev Ashish told me to call
IDispatch::Invoke directly using Matt Curland's TypeLibInfo object on the
member name, but I get an index out of range error in the
following line:

                Call objTLIApp.InvokeHookSub( _
                               m_txt.Parent, _
                               .Item( _
                                    .GetFilteredMembers().Locate( _
                                            m_txt.Name & "_AfterUpdate") _
                                    ).MemberId, _
                                    INVOKE_FUNC)

Specifical the following part is the one giving trouble:

.GetFilteredMembers().Locate( m_txt.Name & "_AfterUpdate")).MemberId

Any help or comments will be highly appreciated.

--
TIA,
T.S.U. Mario Osorio
Punto Fijo, Falcn , Venezuela
Moderador de la lista:
http://www.*-*-*.com/
Pgina personal:
http://www.*-*-*.com/



Mon, 02 Jun 2003 09:40:58 GMT  
 Class raising an event from another class?
Sorry, didn't mean to just vanish on you. Just got caught up in a rush
job.

If you can, send me a zipped mdb with your code. I'll try and puzzle
this out.  I don't think there's an alternative way available for a
private method, unfortunately. In order to get to the member,  you'll
have to inspect it at runtime.   I can't remember for sure, but the
index out of range error means that the object doesn't contain the
member you were looking for (and you should be able to look at this
info by breaking out the embedded typeinfos into individual vars).

  -- Dev


Quote:
> I have the following situation:

> In a form (Form1), I want to create an instance of Class1
> At some point, Class1 needs to execute raise an event in Form1.
> Can this be done? How?

> I posted this question a few days ago and Dev Ashish told me to call
> IDispatch::Invoke directly using Matt Curland's TypeLibInfo object
on the
> member name, but I get an index out of range error in the
> following line:

>                 Call objTLIApp.InvokeHookSub( _
>                                m_txt.Parent, _
>                                .Item( _
>                                     .GetFilteredMembers().Locate( _
>                                             m_txt.Name &
"_AfterUpdate") _
>                                     ).MemberId, _
>                                     INVOKE_FUNC)

> Specifical the following part is the one giving trouble:

> .GetFilteredMembers().Locate( m_txt.Name & "_AfterUpdate")).MemberId

> Any help or comments will be highly appreciated.

> --
> TIA,
> T.S.U. Mario Osorio
> Punto Fijo, Falcn , Venezuela
> Moderador de la lista:
> http://www.egroups.com.mx/group/MS-Access-VBA-Espanol
> Pgina personal:
> http://www.mipagina.cantv.net/hotbudare/



Mon, 02 Jun 2003 09:48:34 GMT  
 Class raising an event from another class?
It's Ok, I thought you were on vacation.

I don't understand what you mean by "(and you should be able to look at this
info by breaking out the embedded typeinfos into individual vars)", but I'm
pretty sure the object does contain the member I'm looking for.

In any case, please donwload the db (116Kb) from:
http://www.mipagina.cantv.net/hotbudare/Downloads/bd3.mdb

I have version 1.10.8169 of TypeLib Information Objects.

--
HTH/EQTA,
T.S.U. Mario Osorio
Punto Fijo, Falcn , Venezuela
Moderador de la lista:
http://www.egroups.com.mx/group/MS-Access-VBA-Espanol
Pgina personal:
http://www.mipagina.cantv.net/hotbudare/



Quote:
> Sorry, didn't mean to just vanish on you. Just got caught up in a rush
> job.

> If you can, send me a zipped mdb with your code. I'll try and puzzle
> this out.  I don't think there's an alternative way available for a
> private method, unfortunately. In order to get to the member,  you'll
> have to inspect it at runtime.   I can't remember for sure, but the
> index out of range error means that the object doesn't contain the
> member you were looking for (and you should be able to look at this
> info by breaking out the embedded typeinfos into individual vars).

>   -- Dev



> > I have the following situation:

> > In a form (Form1), I want to create an instance of Class1
> > At some point, Class1 needs to execute raise an event in Form1.
> > Can this be done? How?

> > I posted this question a few days ago and Dev Ashish told me to call
> > IDispatch::Invoke directly using Matt Curland's TypeLibInfo object
> on the
> > member name, but I get an index out of range error in the
> > following line:

> >                 Call objTLIApp.InvokeHookSub( _
> >                                m_txt.Parent, _
> >                                .Item( _
> >                                     .GetFilteredMembers().Locate( _
> >                                             m_txt.Name &
> "_AfterUpdate") _
> >                                     ).MemberId, _
> >                                     INVOKE_FUNC)

> > Specifical the following part is the one giving trouble:

> > .GetFilteredMembers().Locate( m_txt.Name & "_AfterUpdate")).MemberId

> > Any help or comments will be highly appreciated.

> > --
> > TIA,
> > T.S.U. Mario Osorio
> > Punto Fijo, Falcn , Venezuela
> > Moderador de la lista:
> > http://www.egroups.com.mx/group/MS-Access-VBA-Espanol
> > Pgina personal:
> > http://www.mipagina.cantv.net/hotbudare/



Mon, 02 Jun 2003 10:26:36 GMT  
 Class raising an event from another class?


Quote:
> It's Ok, I thought you were on vacation.

I wish... :-(

Quote:

> I don't understand what you mean by "(and you should be able to look at this
> info by breaking out the embedded typeinfos into individual vars)", but I'm
> pretty sure the object does contain the member I'm looking for.

 And you would be right!  It seems that in my rush, I'd accidentally
(honestly :-)) renamed "private Sub text1_AfterUpdate" to "public Sub
text1_AfterUpdate", which is why it didn't raise an error for me
initially.

I haven't had a chance to completely read the ITypeInfo docs, but it
seems like unless the member is exposed by the object (ie, is public),
COM won't let you get to it's details.  Sorry about the wasted time
and the run around. I'll continue looking and if I find anything, I'll
post it here. In the meantime, it seems like Michel's suggestion of
using Implements is the best solution.

  -- Dev



Fri, 06 Jun 2003 23:23:51 GMT  
 Class raising an event from another class?
Thanks a lot for your time Dev.
I saved Michle's message and, no matter how many times I read it, I still
don't get it. I have never before used Implements, and I swear to God I
don't understand a word about it. I went to ADH, but I think the only
mention it twice in both volumes and help ain't of much help. Would it be
too much if I ask you for an example on how to use the Implements
instructions?

--
TIA,
T.S.U. Mario Osorio
Punto Fijo, Falcn , Venezuela
Moderador de la lista:
http://www.egroups.com.mx/group/MS-Access-VBA-Espanol
Pgina personal:
http://www.mipagina.cantv.net/hotbudare/



Sat, 07 Jun 2003 11:23:14 GMT  
 Class raising an event from another class?
Hi,
If you like I can email you a word
doc on advanced programming
techniques by Ken Getz which includes
examples using the  'Implements' keyword.

Dan

Quote:

> Thanks a lot for your time Dev.
> I saved Michle's message and, no matter how many times I read it, I still
> don't get it. I have never before used Implements, and I swear to God I
> don't understand a word about it. I went to ADH, but I think the only
> mention it twice in both volumes and help ain't of much help. Would it be
> too much if I ask you for an example on how to use the Implements
> instructions?

> --
> TIA,
> T.S.U. Mario Osorio
> Punto Fijo, Falcn , Venezuela
> Moderador de la lista:
> http://www.egroups.com.mx/group/MS-Access-VBA-Espanol
> Pgina personal:
> http://www.mipagina.cantv.net/hotbudare/



Sat, 07 Jun 2003 20:53:11 GMT  
 Class raising an event from another class?
I must have missed part of this thread, but if you're interested in
reacting to events raised by another object, you need the WithEvents
keyword, not Implements.  Perhaps the title of the thread doesn't
currently reflect its intent...

In addition, I'd suggest pointing to either our web site
(www.developershandbook.com), which includes a reasonably up-to-date
list of articles and documents (instead of passing around Word docs,
which may not be current, and don't include the examples), or Dev's web
site (www.mvps.org/access) which includes pretty much the same list. --
Ken



Quote:
> Hi,
> If you like I can email you a word
> doc on advanced programming
> techniques by Ken Getz which includes
> examples using the  'Implements' keyword.

> Dan


> > Thanks a lot for your time Dev.
> > I saved Michle's message and, no matter how many times I read it, I
still
> > don't get it. I have never before used Implements, and I swear to
God I
> > don't understand a word about it. I went to ADH, but I think the
only
> > mention it twice in both volumes and help ain't of much help. Would
it be
> > too much if I ask you for an example on how to use the Implements
> > instructions?

> > --
> > TIA,
> > T.S.U. Mario Osorio
> > Punto Fijo, Falcn , Venezuela
> > Moderador de la lista:
> > http://www.egroups.com.mx/group/MS-Access-VBA-Espanol
> > Pgina personal:
> > http://www.mipagina.cantv.net/hotbudare/

Sent via Deja.com
http://www.deja.com/


Sat, 07 Jun 2003 22:21:01 GMT  
 Class raising an event from another class?
Thank you very much for time. This is my original post. I really hope you
can help me:

In a class module, I'm declaring a module wide variable:
dim tb_Control as textbox

Later on I use a property set function to initialize tb_Control:
property set tb(tbControl as textbox)

    set tb_Control = tbControl
end

Then, in the class_terminate event , I'd like to raise the AfterUpdate event
of tb_Control by checking weather it's a macro or an event procedure. Note
that I don't tb_Control to declare an event for the textbox, I'd only like
to execute the indicated action.

Is it possible? If so: How can this be done??

--
TIA,
T.S.U. Mario Osorio
Punto Fijo, Falcn , Venezuela
Moderador de la lista:
http://www.egroups.com.mx/group/MS-Access-VBA-Espanol
Pgina personal:
http://www.mipagina.cantv.net/hotbudare/



Quote:
> I must have missed part of this thread, but if you're interested in
> reacting to events raised by another object, you need the WithEvents
> keyword, not Implements.  Perhaps the title of the thread doesn't
> currently reflect its intent...

> In addition, I'd suggest pointing to either our web site
> (www.developershandbook.com), which includes a reasonably up-to-date
> list of articles and documents (instead of passing around Word docs,
> which may not be current, and don't include the examples), or Dev's web
> site (www.mvps.org/access) which includes pretty much the same list. --
> Ken



> > Hi,
> > If you like I can email you a word
> > doc on advanced programming
> > techniques by Ken Getz which includes
> > examples using the  'Implements' keyword.

> > Dan


> > > Thanks a lot for your time Dev.
> > > I saved Michle's message and, no matter how many times I read it, I
> still
> > > don't get it. I have never before used Implements, and I swear to
> God I
> > > don't understand a word about it. I went to ADH, but I think the
> only
> > > mention it twice in both volumes and help ain't of much help. Would
> it be
> > > too much if I ask you for an example on how to use the Implements
> > > instructions?

> > > --
> > > TIA,
> > > T.S.U. Mario Osorio
> > > Punto Fijo, Falcn , Venezuela
> > > Moderador de la lista:
> > > http://www.egroups.com.mx/group/MS-Access-VBA-Espanol
> > > Pgina personal:
> > > http://www.mipagina.cantv.net/hotbudare/

> Sent via Deja.com
> http://www.deja.com/



Sun, 08 Jun 2003 08:51:28 GMT  
 Class raising an event from another class?
Thank you very much, Dan ...

--
HTH/EQTA,
T.S.U. Mario Osorio
Punto Fijo, Falcn , Venezuela
Moderador de la lista:
http://www.egroups.com.mx/group/MS-Access-VBA-Espanol
Pgina personal:
http://www.mipagina.cantv.net/hotbudare/



Quote:
> Hi,
> If you like I can email you a word
> doc on advanced programming
> techniques by Ken Getz which includes
> examples using the  'Implements' keyword.

> Dan


> > Thanks a lot for your time Dev.
> > I saved Michle's message and, no matter how many times I read it, I
still
> > don't get it. I have never before used Implements, and I swear to God I
> > don't understand a word about it. I went to ADH, but I think the only
> > mention it twice in both volumes and help ain't of much help. Would it
be
> > too much if I ask you for an example on how to use the Implements
> > instructions?

> > --
> > TIA,
> > T.S.U. Mario Osorio
> > Punto Fijo, Falcn , Venezuela
> > Moderador de la lista:
> > http://www.egroups.com.mx/group/MS-Access-VBA-Espanol
> > Pgina personal:
> > http://www.mipagina.cantv.net/hotbudare/



Sun, 08 Jun 2003 08:52:10 GMT  
 Class raising an event from another class?
Well, if you want to trap events of the text box in your class, you can
use

Private WithEvents tb_Control As TextBox

THen, you can add event procedures for tb_Control in this class. You
cannot, however, RAISE an event from the Terminate event of your class.
I forget the details, but this is a no-no, I believe (could be wrong,
but I'm pretty sure...)

But you don't need to do this, if all you want to do is execute its
AfterUpdate event. It's not clear what you're trying to do, but you can
check the AfterUpdate property for one of three things:

1. If you find "[Event Procedure]" in there, you know it's an event
procedure.
2. If you find "=FunctionName()", you know it's calling a function in
reaction to the event.
3. Anything else must be a macro name.

In any case, raising the AfterUpdate event WILL NOT call that code. I
may not be thinking straight, but I can't think of a 100% effective way
to call that code. I know that I figured out a way that worked most of
the time, in the Access 97 Developer's Handbook (I think I worked this
out a different way in the Access 2000 book), that involved using the
Eval function, but I have a feeling it didn't work in every case.

In other words, your question may have led us off down the incorrect
path -- raising the event won't help, and WithEvents only lets you
react to events of the object you're shadowing (that is, reacting to
the AfterUpdate event of the text box in your class, for example). --
Ken



Quote:
> Thank you very much for time. This is my original post. I really hope
you
> can help me:

> In a class module, I'm declaring a module wide variable:
> dim tb_Control as textbox

> Later on I use a property set function to initialize tb_Control:
> property set tb(tbControl as textbox)

>     set tb_Control = tbControl
> end

> Then, in the class_terminate event , I'd like to raise the
AfterUpdate event
> of tb_Control by checking weather it's a macro or an event procedure.
Note
> that I don't tb_Control to declare an event for the textbox, I'd only
like
> to execute the indicated action.

> Is it possible? If so: How can this be done??

> --
> TIA,
> T.S.U. Mario Osorio
> Punto Fijo, Falcn , Venezuela
> Moderador de la lista:
> http://www.egroups.com.mx/group/MS-Access-VBA-Espanol
> Pgina personal:
> http://www.mipagina.cantv.net/hotbudare/



> > I must have missed part of this thread, but if you're interested in
> > reacting to events raised by another object, you need the WithEvents
> > keyword, not Implements.  Perhaps the title of the thread doesn't
> > currently reflect its intent...

> > In addition, I'd suggest pointing to either our web site
> > (www.developershandbook.com), which includes a reasonably up-to-date
> > list of articles and documents (instead of passing around Word docs,
> > which may not be current, and don't include the examples), or Dev's
web
> > site (www.mvps.org/access) which includes pretty much the same
list. --
> > Ken



> > > Hi,
> > > If you like I can email you a word
> > > doc on advanced programming
> > > techniques by Ken Getz which includes
> > > examples using the  'Implements' keyword.

> > > Dan


> > > > Thanks a lot for your time Dev.
> > > > I saved Michle's message and, no matter how many times I read
it, I
> > still
> > > > don't get it. I have never before used Implements, and I swear
to
> > God I
> > > > don't understand a word about it. I went to ADH, but I think the
> > only
> > > > mention it twice in both volumes and help ain't of much help.
Would
> > it be
> > > > too much if I ask you for an example on how to use the
Implements
> > > > instructions?

> > > > --
> > > > TIA,
> > > > T.S.U. Mario Osorio
> > > > Punto Fijo, Falcn , Venezuela
> > > > Moderador de la lista:
> > > > http://www.egroups.com.mx/group/MS-Access-VBA-Espanol
> > > > Pgina personal:
> > > > http://www.mipagina.cantv.net/hotbudare/

> > Sent via Deja.com
> > http://www.deja.com/

Sent via Deja.com
http://www.deja.com/


Sun, 08 Jun 2003 09:42:45 GMT  
 Class raising an event from another class?
It's not event trapping I need; I have to raise the AfterUpdate event of
that text box. About doing it from the Terminate event, I could work it out.
My class will change the value of tb_Control while it has focus, so all I
want to do is to properly do whatever the control has in it's AfterUpdate
property.
This is how I have solved it, just a few minutes ago:
My class was originally changing tb_Control's value only while it had focus,
so I changed it to change the Text property of tb_Control and the
AfterUpdate event, macro or whatever run as expected.
I still think my original question is very interesting: what if the class
needed to raise any other event not as easy to raise as the AfterUpdate?

--
TIA,
T.S.U. Mario Osorio
Punto Fijo, Falcn , Venezuela
Moderador de la lista:
http://www.egroups.com.mx/group/MS-Access-VBA-Espanol
Pgina personal:
http://www.mipagina.cantv.net/hotbudare/



Quote:
> Well, if you want to trap events of the text box in your class, you can
> use

> Private WithEvents tb_Control As TextBox

> THen, you can add event procedures for tb_Control in this class. You
> cannot, however, RAISE an event from the Terminate event of your class.
> I forget the details, but this is a no-no, I believe (could be wrong,
> but I'm pretty sure...)

> But you don't need to do this, if all you want to do is execute its
> AfterUpdate event. It's not clear what you're trying to do, but you can
> check the AfterUpdate property for one of three things:

> 1. If you find "[Event Procedure]" in there, you know it's an event
> procedure.
> 2. If you find "=FunctionName()", you know it's calling a function in
> reaction to the event.
> 3. Anything else must be a macro name.

> In any case, raising the AfterUpdate event WILL NOT call that code. I
> may not be thinking straight, but I can't think of a 100% effective way
> to call that code. I know that I figured out a way that worked most of
> the time, in the Access 97 Developer's Handbook (I think I worked this
> out a different way in the Access 2000 book), that involved using the
> Eval function, but I have a feeling it didn't work in every case.

> In other words, your question may have led us off down the incorrect
> path -- raising the event won't help, and WithEvents only lets you
> react to events of the object you're shadowing (that is, reacting to
> the AfterUpdate event of the text box in your class, for example). --
> Ken



> > Thank you very much for time. This is my original post. I really hope
> you
> > can help me:

> > In a class module, I'm declaring a module wide variable:
> > dim tb_Control as textbox

> > Later on I use a property set function to initialize tb_Control:
> > property set tb(tbControl as textbox)

> >     set tb_Control = tbControl
> > end

> > Then, in the class_terminate event , I'd like to raise the
> AfterUpdate event
> > of tb_Control by checking weather it's a macro or an event procedure.
> Note
> > that I don't tb_Control to declare an event for the textbox, I'd only
> like
> > to execute the indicated action.

> > Is it possible? If so: How can this be done??

> > --
> > TIA,
> > T.S.U. Mario Osorio
> > Punto Fijo, Falcn , Venezuela
> > Moderador de la lista:
> > http://www.egroups.com.mx/group/MS-Access-VBA-Espanol
> > Pgina personal:
> > http://www.mipagina.cantv.net/hotbudare/



> > > I must have missed part of this thread, but if you're interested in
> > > reacting to events raised by another object, you need the WithEvents
> > > keyword, not Implements.  Perhaps the title of the thread doesn't
> > > currently reflect its intent...

> > > In addition, I'd suggest pointing to either our web site
> > > (www.developershandbook.com), which includes a reasonably up-to-date
> > > list of articles and documents (instead of passing around Word docs,
> > > which may not be current, and don't include the examples), or Dev's
> web
> > > site (www.mvps.org/access) which includes pretty much the same
> list. --
> > > Ken



> > > > Hi,
> > > > If you like I can email you a word
> > > > doc on advanced programming
> > > > techniques by Ken Getz which includes
> > > > examples using the  'Implements' keyword.

> > > > Dan


> > > > > Thanks a lot for your time Dev.
> > > > > I saved Michle's message and, no matter how many times I read
> it, I
> > > still
> > > > > don't get it. I have never before used Implements, and I swear
> to
> > > God I
> > > > > don't understand a word about it. I went to ADH, but I think the
> > > only
> > > > > mention it twice in both volumes and help ain't of much help.
> Would
> > > it be
> > > > > too much if I ask you for an example on how to use the
> Implements
> > > > > instructions?

> > > > > --
> > > > > TIA,
> > > > > T.S.U. Mario Osorio
> > > > > Punto Fijo, Falcn , Venezuela
> > > > > Moderador de la lista:
> > > > > http://www.egroups.com.mx/group/MS-Access-VBA-Espanol
> > > > > Pgina personal:
> > > > > http://www.mipagina.cantv.net/hotbudare/

> > > Sent via Deja.com
> > > http://www.deja.com/

> Sent via Deja.com
> http://www.deja.com/



Sun, 08 Jun 2003 10:54:35 GMT  
 Class raising an event from another class?


: This is how I have solved it, just a few minutes ago:
: My class was originally changing tb_Control's value only while it
had focus,
: so I changed it to change the Text property of tb_Control and the
: AfterUpdate event, macro or whatever run as expected.

Nice!  I'd completely forgotten about changing the property that
AfterUpdate looks for to simulate RaiseEvents.  "Forest and trees",
perhaps. ;-)

: I still think my original question is very interesting: what if the
class
: needed to raise any other event not as easy to raise as the
AfterUpdate?

I do intend to revisit this (as soon as my schedule clears up) as I
found it just as interesting. We know the information is out there.
First I was thinking that the Object Browser must be doing it the COM
way to boldface private events for a form/report in the current
project, but now I think it must be using the Extensibility model in
conjunction with ITypeInfo data to do this (unless there's a COM way
that I've missed in my readings thus far).

  -- Dev



Sun, 08 Jun 2003 20:47:18 GMT  
 Class raising an event from another class?

Quote:
> I do intend to revisit this (as soon as my schedule clears up) as I
> found it just as interesting.

==>> Please keep me informed of any findings on tjhis issue.

Quote:
> We know the information is out there.
> First I was thinking that the Object Browser must be doing it the COM
> way to boldface private events for a form/report in the current
> project, but now I think it must be using the Extensibility model in
> conjunction with ITypeInfo data to do this (unless there's a COM way
> that I've missed in my readings thus far).

==>> This is chinese for me :-]

--
Thanks,
T.S.U. Mario Osorio
Punto Fijo, Falcn , Venezuela
Moderador de la lista:
http://www.egroups.com.mx/group/MS-Access-VBA-Espanol
Pgina personal:
http://www.mipagina.cantv.net/hotbudare/



Quote:



> : This is how I have solved it, just a few minutes ago:
> : My class was originally changing tb_Control's value only while it
> had focus,
> : so I changed it to change the Text property of tb_Control and the
> : AfterUpdate event, macro or whatever run as expected.

> Nice!  I'd completely forgotten about changing the property that
> AfterUpdate looks for to simulate RaiseEvents.  "Forest and trees",
> perhaps. ;-)

> : I still think my original question is very interesting: what if the
> class
> : needed to raise any other event not as easy to raise as the
> AfterUpdate?

> I do intend to revisit this (as soon as my schedule clears up) as I
> found it just as interesting. We know the information is out there.
> First I was thinking that the Object Browser must be doing it the COM
> way to boldface private events for a form/report in the current
> project, but now I think it must be using the Extensibility model in
> conjunction with ITypeInfo data to do this (unless there's a COM way
> that I've missed in my readings thus far).

>   -- Dev



Mon, 09 Jun 2003 10:11:15 GMT  
 
 [ 14 post ] 

 Relevant Pages 

1. Raising events from a class within a collection class

2. Make your class fire an Event ( custom class event, RaiseEvent )

3. raising events in another class

4. How to raise events in other classes?

5. Raising button click events in the same class

6. Raising events from a class

7. how to raise base class event and method from the derived child object

8. Raise base class events or override them

9. array of classes and raising events

10. Raise Event in Class From Callback

11. Again: Can't raise events from the class

12. Again: Can't raise events from the class

 

 
Powered by phpBB® Forum Software