I have an event declared in class1
Now i want to raise the event in the my class2 or anywhere other than class1
Is it possible? If so how
Thank you 5 1573
"Santhoshi" <an*******@disc ussions.microso ft.com> wrote in message
news:F3******** *************** ***********@mic rosoft.com... I have an event declared in class1.
Now i want to raise the event in the my class2 or anywhere other than class1.
Is it possible? If so how?
Basically you will have to declare a method on class1 that can raise the
event. Thank you
Hi Santhosi,
You have to declare your event "public"
I hope this helps?
Cor
"Cor" <no*@non.com> wrote in message
news:OX******** **********@TK2M SFTNGP10.phx.gb l... Hi Santhosi,
You have to declare your event "public"
I hope this helps?
Public is actually irrelevent. The event keyword(in C# anyway, don't see VB
being that different) is specifically used over a plain delegate type
because it restricts outside classes from raising or clearing the event,
otherwise a plain delegate would suffice. This creates an event in the
assembly, this event has two required methods (add and remove in C#, .addon
and .removeon in IL) that performs the addition and removal of a delegate
from the event. Even when the event is declared as a field underneath it is
a property with a backing delegate field(compiler handles that). Because of
this, an event type *never* directly provides access to the backing
delegate, in fact code has no way to actually get to the backing delegate
because of the nature of events.
Now, there is a raise accessor defined by the CLI spec, specifically .fire
in IL, but the recommendation is for that accessor to be protected and it
isn't surfaced in C# and VB(AFAIK). This accessor doesn't have a restriction
that it *must* be protected, to my knowledge, and if you use a language that
allows public raise accessors, it will be possible to raise the event from
another class, otherwise you are basically out of luck(note, C# doesn't
consume raise accessors in my experience).
It really is simplier to simply write a method to do what you want(thats
basically all a raise accessor is, after all). Cor
Hi Daniel,
Can you try this (needs only to open the ide, start a VB project and paste
it in, and set the start in your properties to sub main), and then give
comments, I did it in VB, because there was my answer based on.
This was the question
I have an event declared in class1.
Now i want to raise the event in the my class2 or anywhere other than
class1.
Is it possible? If so how?
This was my answer
You have to declare your event "public"
I am curious to your answer
Cor
This is my sample.
\\\
Public Class class1
Public Event Hello()
Public Sub sayhello()
RaiseEvent Hello()
End Sub
End Clas
Public Module class2
Private WithEvents myhi As New class1
Public Sub Main()
myhi.sayhello()
End Sub
Private Sub hihi() Handles myhi.Hello
MessageBox.Show ("Hello Daniel")
End Sub
End Module
///
Cor <no*@non.com> wrote: Can you try this (needs only to open the ide, start a VB project and paste it in, and set the start in your properties to sub main), and then give comments, I did it in VB, because there was my answer based on.
This was the question I have an event declared in class1. Now i want to raise the event in the my class2 or anywhere other than class1. Is it possible? If so how? This was my answer You have to declare your event "public"
You don't have to declare the event public in order to *raise* the
event. You have to declare the event public in order to *subscribe* to
(or unsubscribe from) it.
The reason your code allows other classes to raise the events is
because you've *also* given a sayhello method. It would be possible to
give that method without the Hello event being public, in which case
only the class could subscribe to the event, but anyone could raise it
(indirectly, via the method call).
--
Jon Skeet - <sk***@pobox.co m> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Rajesh.V |
last post by:
I have made a custom control in asp.net using webcontrols, and am raising my
event. I find that if no control is hooked into the event it goes for a
toss. I tried to find length of the delegate array returned by
ButtonClicked.GetInvocationList method
event that is raising an exception. Presently i am enclosing in try catch
block and would like to avoid that. Any suggestions on how to find if any
body is hooked/listening to this event.
|
by: Dan |
last post by:
I've created a pocketpc app which has a startup form containing a listview.
The form creates an object which in turn creates a System.Threading.Timer.
It keeps track of the Timer state using a TimerState object similar to the
example in the System.Threading.Timer documentation. The method which
handles the timer events, among other things, periodically calls a method in
this TimerState object which raises an event to the startup form,...
|
by: rawCoder |
last post by:
Hi all,
How Can You Raise Events Asynchronously ?
Now for the details ...
I want to do inter modular communication using events in such a way that the
contributing modules need not maintain the reference to any module.
|
by: Joe Campbell |
last post by:
I am encountering a problem raising WMI events from an
asp.net application. The error received (as captured in
the event log) is as follows:
System.Runtime.InteropServices.COMException (0x80041003):
Exception from HRESULT: 0x80041003.
at
Microsoft.EnterpriseInstrumentation.EventSinks.WmiEventSink
..Write(Object eventToRaise)
at
|
by: Dave A |
last post by:
I am developing a somewhat complex component at the moment and coincidently
I am also reading the Framework Design Guidelines book.
After reading the section about event raising I have re-written the way my
component raises events to follow the Framework Design Guides verbatim; ie
(object sender, EventArgs (or some subclass there of) e).
The thing that was not explained is why should I need to cast the sender to
'object' when I know...
| |
by: Gman |
last post by:
Hi,
I have created a usercontrol, a grid control essentially. Within it I
have a class: clsGridRecord. I have coded the events such that when a
user clicks on the grid, say, the events occur on the parent form. This
is fine.
The problem occurs when I want to raise an event for a user clicking on
one of the clsRecords which are on the grid. So I've placed:
Public Event GridRecordClicked(ByVal rec As clsGridRecord,
|
by: sloan |
last post by:
I"m trying to figure out what concept I'm missing here, or if its not a good
idea .. or what.
Here is my example.. code is below.
I have an employee class.
It has an event that can be raised.
In the constructor, I check the to see if the employees birthday is today.
If it is today, then I raise an event.
|
by: =?Utf-8?B?Um9i?= |
last post by:
I'm new to event processing in vs 2005 - what I'm trying to achieve is
broadly a network simulation of two workstations sending packets to each
other .
I have defined a class 'Workstation' and I was hoping to define events where
in instance A (or workstation) I could raise an event 'Send' (which takes in
the destination instance B (or workstation) and the Packet to send). The
event would then trigger a 'Receive' event in instance B to...
|
by: Christian Cambier |
last post by:
Hi,
I have a textbox in a web user control.
I then add the usercontrol to a web form. I also add a label in the
web form.
Now, when I press a key in the textbox, i want to display some text in
the label.
I tried by raising events as used in Winforms but it is not as easy as
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |