Hi Everyone,
I have built a class module that fires some events given specific
circumstances. When I step through the code the RaiseEvent EventName
is called, and the event is declared in the class as Public
EventName(). Pretty standard stuff it would seem.
I am tring to build a wrapper class (actually a form) around this. The
form is (in theory) going to display feedaback from the class as it
does its work while also allowing control of the class. I started with
a simple blank form, eliminated the pivot view and other views leaving
only form view, set the border style to thin, removed the control box,
and thats about it (set the caption too). Saved this simple form and
gave it a sensible name. No controls on the form at this time.
In the forms declarations section I declare a variable for my class
as:
Private WithEvents VariableName as ClassName
In the forms OnLoad event I have this:
Set VariableName = new ClassName
When I step through the code I can see that the class does in fact get
initialised. Cool I think to myself.
I select the VariableName object in the drop down, and select the
'Initialised' event. This event is declared as Public Event
Initialised() in the class's declarations. The RaiseEvent
Initialised() is called at the end of the class's initialisation -
this is the code I stepped through and the RaiseEvent line of code is
being called without error. In the forms VariableName_Initialised
event code I have a simple debug.print "Started". I never see the
output from this in the immediate window. As I step through the code
the event code on the form for this event is never reached.
Have I done something wrong here? I can post the code for the class if
necessary (a bit long), and all I have on the form is what is above.
As I understand it these events should be firing when called, but
arent. Am I missing something?
Any help appreciated
Cheers
The Frog
|
|
0
|
|
|
|
Reply
|
mr.frog.to.you (503)
|
4/1/2010 9:16:14 AM |
|
OK, Ok, sorry everyone. It seems that my brain is more eager to get
things done than my common sense. It is not possible to rasie an event
during class initialisation or termination. This is of course why it
isnt doing anything :-)
Then the issue becomes - what is an effective workaround for this? I
need to create a notofication when the class has completed its
initialisation. Same with the termination of the class.
Any help appreciated.
Cheers
The Frog
|
|
0
|
|
|
|
Reply
|
The
|
4/1/2010 12:00:19 PM
|
|
On Thu, 1 Apr 2010 05:00:19 -0700 (PDT), The Frog
<mr.frog.to.you@googlemail.com> wrote:
It seems to me after:
Set VariableName = new ClassName
the class (better: object) is created and ready to use. You could
write:
Set VariableName = new ClassName
Call Initialized()
The other thing I have done is make the constructor and destructor
extremely light-weight (essentially no-ops), and add an Init and Exit
method to do the initialization and cleanup of the object. THOSE
methods can raise events. The developer would need to know to call
these methods, or you can call them (at least Init) at each normal
method call if Init had not yet been called:
public method DoSomething
if _HasInitBeenCalled = false then
call Init()
end if
(Init would set this boolean value)
-Tom.
Microsoft Access MVP
>OK, Ok, sorry everyone. It seems that my brain is more eager to get
>things done than my common sense. It is not possible to rasie an event
>during class initialisation or termination. This is of course why it
>isnt doing anything :-)
>
>Then the issue becomes - what is an effective workaround for this? I
>need to create a notofication when the class has completed its
>initialisation. Same with the termination of the class.
>
>Any help appreciated.
>
>Cheers
>
>The Frog
|
|
0
|
|
|
|
Reply
|
Tom
|
4/2/2010 3:10:20 AM
|
|
"Tom van Stiphout" <tom7744.no.spam@cox.net> wrote in message
news:vlnar5pbm4odn7pg0prhdis4mo7l8h0pu7@4ax.com...
> On Thu, 1 Apr 2010 05:00:19 -0700 (PDT), The Frog
> <mr.frog.to.you@googlemail.com> wrote:
>
> It seems to me after:
> Set VariableName = new ClassName
> the class (better: object) is created and ready to use. You could
> write:
> Set VariableName = new ClassName
> Call Initialized()
>
> The other thing I have done is make the constructor and destructor
> extremely light-weight (essentially no-ops), and add an Init and Exit
> method to do the initialization and cleanup of the object. THOSE
> methods can raise events. The developer would need to know to call
> these methods, or you can call them (at least Init) at each normal
> method call if Init had not yet been called:
> public method DoSomething
> if _HasInitBeenCalled = false then
> call Init()
> end if
> (Init would set this boolean value)
>
> -Tom.
> Microsoft Access MVP
Sounds like a plan, although if I might make a suggestion, the
_HasInitBeenCalled variable could be a static var in the Init routine, the
1st line of which would check it and exit the proc if True. That way the
methods need only call the Init routine instead of doing the checking in
more than one place.
>
>
>
>>OK, Ok, sorry everyone. It seems that my brain is more eager to get
>>things done than my common sense. It is not possible to rasie an event
>>during class initialisation or termination. This is of course why it
>>isnt doing anything :-)
>>
>>Then the issue becomes - what is an effective workaround for this? I
>>need to create a notofication when the class has completed its
>>initialisation. Same with the termination of the class.
>>
>>Any help appreciated.
>>
>>Cheers
>>
>>The Frog
|
|
0
|
|
|
|
Reply
|
Stuart
|
4/2/2010 4:16:31 AM
|
|
On Fri, 2 Apr 2010 05:16:31 +0100, "Stuart McCall"
<smccall@myunrealbox.com> wrote:
Good point!
-Tom.
Microsoft Access MVP
>"Tom van Stiphout" <tom7744.no.spam@cox.net> wrote in message
>news:vlnar5pbm4odn7pg0prhdis4mo7l8h0pu7@4ax.com...
>> On Thu, 1 Apr 2010 05:00:19 -0700 (PDT), The Frog
>> <mr.frog.to.you@googlemail.com> wrote:
>>
>> It seems to me after:
>> Set VariableName = new ClassName
>> the class (better: object) is created and ready to use. You could
>> write:
>> Set VariableName = new ClassName
>> Call Initialized()
>>
>> The other thing I have done is make the constructor and destructor
>> extremely light-weight (essentially no-ops), and add an Init and Exit
>> method to do the initialization and cleanup of the object. THOSE
>> methods can raise events. The developer would need to know to call
>> these methods, or you can call them (at least Init) at each normal
>> method call if Init had not yet been called:
>> public method DoSomething
>> if _HasInitBeenCalled = false then
>> call Init()
>> end if
>> (Init would set this boolean value)
>>
>> -Tom.
>> Microsoft Access MVP
>
>Sounds like a plan, although if I might make a suggestion, the
>_HasInitBeenCalled variable could be a static var in the Init routine, the
>1st line of which would check it and exit the proc if True. That way the
>methods need only call the Init routine instead of doing the checking in
>more than one place.
>
>>
>>
>>
>>>OK, Ok, sorry everyone. It seems that my brain is more eager to get
>>>things done than my common sense. It is not possible to rasie an event
>>>during class initialisation or termination. This is of course why it
>>>isnt doing anything :-)
>>>
>>>Then the issue becomes - what is an effective workaround for this? I
>>>need to create a notofication when the class has completed its
>>>initialisation. Same with the termination of the class.
>>>
>>>Any help appreciated.
>>>
>>>Cheers
>>>
>>>The Frog
>
|
|
0
|
|
|
|
Reply
|
Tom
|
4/2/2010 4:21:17 AM
|
|
I can think of a way to get a message when a class is terminated.
I think you may just have to make the assumption that it is Initiated
when you set
the object variable.
The termination solution involves another class contained by the first
class. The contained
class actually raises the event. The following code is a minimal,
functional demo.
[class1]
Option Compare Database
Option Explicit
Private n As clsNotify
Public Property Set notify(nt As clsNotify)
Set n = nt
End Property
Private Sub Class_Terminate()
n.CallNotify
End Sub
[/class1]
[clsNotify]
Option Compare Database
Option Explicit
Public Event notify(note As String)
Public Sub CallNotify()
RaiseEvent notify("Terminated")
End Sub
[/clsNotify]
[form1]
Option Compare Database
Option Explicit
Private c As class1
Private WithEvents n As clsNotify
Private Sub Command3_Click()
Set c = New class1
Set n = New clsNotify
Set c.notify = n
End Sub
Private Sub Command4_Click()
Set c = Nothing
End Sub
Private Sub n_notify(note As String)
Me.Text1.Value = note
End Sub
[/form1]
|
|
0
|
|
|
|
Reply
|
rkc
|
4/5/2010 3:21:52 AM
|
|
|
5 Replies
370 Views
(page loaded in 0.102 seconds)
Similiar Articles: JComboBox - knowing when the selection has changed - comp.lang ...I know ... the very useful 'JComboBox' Class does not have ... JTree: ValueChanged event not firing - comp.lang.java ... Once again, it seems that something has changed in ... Need software for c8000 with FireGL X3 - comp.sys.hp.hpux ...Are the "PC" versions of the Fire-series working or ... PS finding some extra hds to put inside seems an ... not open (some applets on the taskbar) or some modules do not ... Annoying kernel memory leak in U6? - comp.unix.solaris... with all the latest patches). System is a Sun Fire T... ... something similar on a X4500 server too that also seems ... 16 0 10 0 devfsadm_event_channel ... C++ wrapper for async socket calls. - comp.unix.programmer ...... for anything and Graham Barr's poll module is ... I did some googling it seems its support is limited and not stable. ... The NetworkStream class is a wrapper around ... Misuses of RTTI - comp.lang.c++.moderatedUsually, RTTI is not needed, e.g.: class A {}; class B : A ... to maintain (that is, you add a new event type, you are not ... can't be a useful tool, just that it seems ... Packet timestamps when using Windows-7/Vista - comp.protocols.time ...> > The difference in Vista/7 vs. 2000/XP seems to be that ... systems: PC Gemini: Level,Date and Time,Source,Event ... 07:16:00,NTP,3,None,Raised to realtime priority class ... Which Assembler? - comp.lang.asm.x86... will have some value. I am not new to ... war, and are based on observable events ... much more of a lower quality/class assembler. RosASM is Win32/PE specific, does not ... PDMworks and DBworks?? - comp.cad.solidworksThis module basically allows access to the PDM/Works API ... and out (hope you didn't fall asleep in the SW class ... interface is far better than the actual one. it seems ... Does PAUSE have any Side Effect ?? - comp.lang.fortranIt seems that might count as an I/O operation, and also ... One of the most difficult class of bugs to locate and ... Contains and one explicit Interface, but no > > > modules ... Tobit LAN!Time DCF77 receiver not working - comp.protocols.time ...... DCF-77 serial port receiver but this device will not ... These are results from April 2009 using Conrad module ... 1 u 10 128 377 35.681 33.177 3.585 It seems i ... Class module events not firing (it seems)..... DataBaseHi Everyone, I have built a class module that fires some events given specific circumstances. When I step through the code the RaiseEvent EventName is ca ListBox DblClick event not firing within class module - Microsoft ...ListBox DblClick event not firing within class module. Microsoft Access / VBA Forums on Bytes. 7/24/2012 10:33:24 AM
|