msvisual.com Forum Index
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Events in Implement interface

 
Post new topic   Reply to topic    msvisual.com Forum Index -> VB Enterprise
Author Message
John Fors



Joined: 04 Oct 2007
Posts: 3

PostPosted: Mon Sep 08, 2003 3:46 pm    Post subject: Events in Implement interface Reply with quote

I have a program which has several class' sharing an implemented interface.
I would like this reference to the implemented interface to be able to
recieve an event.

My interface definition for what I call "DynCalc" looks like this:
*************************************************start code sample
' Generalized Calculation with stubbed out procedures
' for the real calculation classes to use as a implements.

Public Event Change(CalcChange As DynCalc)

Public Sub Calculate()
' Run the special code to do the calculation then call all the dependent
calculation in the
' mRegisteredCalcs collection.
End Sub
*************************************************end code sample


My definition of a class named "EventCalc" with an implemented class looks
like this
*************************************************start code sample
Option Explicit

Implements DynCalc
Public Event Change(CalcChange As DynCalc)
Private Sub DynCalc_Calculate()
'some code here

RaiseEvent Change(Me)

' some other code

End sub

*************************************************end code sample
My code currently returns an error when setting a reference to the EventCalc
class with a variable dim'd withevents.

******************error

Dim withEvents XYZ as DynCalc
Set XYZ = GetCalc("IndentifyingString") 'runtime error here
? err.Description
Object or class does not support the set of events
? Err.Number
459
******************end error
Which makes sense to me since the code has noway to know if the change event
is
defined to be part of the class or the implemented interface. Question?
Does an
interface have the event as part of it or is an event only part of a class?
Defining the event in the class with the following syntax returns an syntax
error

Public Event DynCalc_Change(CalcChange As DynCalc)

Error is you can't have an underscore in an event declaration

Can somebody help me understand how or if this can be done?
Thanks for all your help in advance

John

Archived from group: microsoft>public>vb>com
Back to top
View user's profile Send private message
Willy Van den Driessche



Joined: 04 Oct 2007
Posts: 2

PostPosted: Tue Sep 09, 2003 12:39 am    Post subject: Re: Events in Implement interface Reply with quote

I personally use an "event channel object" as in
http://users.skynet.be/wvdd2/General_techniques/Interfaces_Withevents/interfaces_withevents.html

Matthew curland's book (www.powervb.com) shows you how interfaces can do
real events (there's a link to a discussion at the bottom of my page ).
--
For a work in progress :
http://users.skynet.be/wvdd2/
"John Fors" schreef in bericht@TK2MSFTNGP11.phx.gbl...
> I have a program which has several class' sharing an implemented
interface.
> I would like this reference to the implemented interface to be able to
> recieve an event.
>
> My interface definition for what I call "DynCalc" looks like this:
> *************************************************start code sample
> ' Generalized Calculation with stubbed out procedures
> ' for the real calculation classes to use as a implements.
>
> Public Event Change(CalcChange As DynCalc)
>
> Public Sub Calculate()
> ' Run the special code to do the calculation then call all the dependent
> calculation in the
> ' mRegisteredCalcs collection.
> End Sub
> *************************************************end code sample
>
>
> My definition of a class named "EventCalc" with an implemented class looks
> like this
> *************************************************start code sample
> Option Explicit
>
> Implements DynCalc
> Public Event Change(CalcChange As DynCalc)
> Private Sub DynCalc_Calculate()
> 'some code here
>
> RaiseEvent Change(Me)
>
> ' some other code
>
> End sub
>
> *************************************************end code sample
> My code currently returns an error when setting a reference to the
EventCalc
> class with a variable dim'd withevents.
>
> ******************error
>
> Dim withEvents XYZ as DynCalc
> Set XYZ = GetCalc("IndentifyingString") 'runtime error here
> ? err.Description
> Object or class does not support the set of events
> ? Err.Number
> 459
> ******************end error
> Which makes sense to me since the code has noway to know if the change
event
> is
> defined to be part of the class or the implemented interface. Question?
> Does an
> interface have the event as part of it or is an event only part of a
class?
> Defining the event in the class with the following syntax returns an
syntax
> error
>
> Public Event DynCalc_Change(CalcChange As DynCalc)
>
> Error is you can't have an underscore in an event declaration
>
> Can somebody help me understand how or if this can be done?
> Thanks for all your help in advance
>
> John
>
>
>
>
Back to top
View user's profile Send private message
John Fors



Joined: 04 Oct 2007
Posts: 3

PostPosted: Tue Sep 09, 2003 1:06 pm    Post subject: Re: Events in Implement interface Reply with quote

thanks Willy Van den Driessche

After reading your reply I dug out my copy of Hardcore Visual Basic cd and
tried to use the method of redirecting VB to the event list. I
unfortunately didn't have an uptodate cd and lost the book years ago on a
plane.

So I took on your method. The method implemented easily and was easily
understood. I personally think if I worked in a big developement firm I
would use the redirection method. Your method is what I will use for now on
my developement project in this one man company.

John Fors
Back to top
View user's profile Send private message
Willy Van den Driessche



Joined: 04 Oct 2007
Posts: 2

PostPosted: Wed Sep 10, 2003 12:42 am    Post subject: Re: Events in Implement interface Reply with quote

"John Fors" schreef in bericht@TK2MSFTNGP09.phx.gbl...
> thanks Willy Van den Driessche
>
> After reading your reply I dug out my copy of Hardcore Visual Basic cd and
> tried to use the method of redirecting VB to the event list. I
> unfortunately didn't have an uptodate cd and lost the book years ago on a
> plane.
>
> So I took on your method. The method implemented easily and was easily
> understood. I personally think if I worked in a big developement firm I
> would use the redirection method. Your method is what I will use for now
on
> my developement project in this one man company.
It's a matter of taste really. Our project is + 500 KLoc of VB code and my
approach didn't hurt. The most important benefit is that it's easy to
explain to fellow programmers.
>
> John Fors
>
>

Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    msvisual.com Forum Index -> VB Enterprise All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group