473,396 Members | 2,026 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

What is the 'Object' of these calls?

I've written a few event handler methods in my time. Most of them are of the
general form:

void EventHandler( Object^ o, EventArgs^ e )
{
}

However, in all of these I've written, and in every example I've ever seen
on MSDN, the "Object^ o" is NEVER used! What exactly is it, and why is it
there if even MS never seems to use it?

Every example I've seen lists it as 'Object^ /*sender*/', indicating it is
the 'sender' (whatever that means), and it's parameter being commented out
means it doesn't seem like it is ever used. Since it is of type Object^ I'm
guessing it must be typecast to be at all useful.

Most sample code, and everything I've ever written just strips this Object
paramater out or ignores it, and nothing seems to go wrong.

What is it for, and when/how is it useful?

[==Peter==]
Oct 8 '07 #1
2 1131
The Object^ parameter is useful when you handle more than one object with the
same handler. Also it's necessary when the event is raised by an object that is
out of your control (when you don't have a direct controller variable).

Regards

--
Cholo Lennon
Bs.As.
ARG
"Peter Oliphant" <po*******@roundtripllc.comwrote in message
news:OB**************@TK2MSFTNGP05.phx.gbl...
I've written a few event handler methods in my time. Most of them are of the
general form:

void EventHandler( Object^ o, EventArgs^ e )
{
}

However, in all of these I've written, and in every example I've ever seen
on MSDN, the "Object^ o" is NEVER used! What exactly is it, and why is it
there if even MS never seems to use it?

Every example I've seen lists it as 'Object^ /*sender*/', indicating it is
the 'sender' (whatever that means), and it's parameter being commented out
means it doesn't seem like it is ever used. Since it is of type Object^ I'm
guessing it must be typecast to be at all useful.

Most sample code, and everything I've ever written just strips this Object
paramater out or ignores it, and nothing seems to go wrong.

What is it for, and when/how is it useful?

[==Peter==]


Oct 8 '07 #2

"Peter Oliphant" <po*******@roundtripllc.comwrote in message
news:OB**************@TK2MSFTNGP05.phx.gbl...
I've written a few event handler methods in my time. Most of them are of
the general form:

void EventHandler( Object^ o, EventArgs^ e )
{
}

However, in all of these I've written, and in every example I've ever seen
on MSDN, the "Object^ o" is NEVER used! What exactly is it, and why is it
there if even MS never seems to use it?

Every example I've seen lists it as 'Object^ /*sender*/', indicating it is
the 'sender' (whatever that means), and it's parameter being commented out
means it doesn't seem like it is ever used. Since it is of type Object^
I'm guessing it must be typecast to be at all useful.

Most sample code, and everything I've ever written just strips this Object
paramater out or ignores it, and nothing seems to go wrong.

What is it for, and when/how is it useful?
Typically, it is the object you subscribed to. For example:

Button^ b;
b->Clicked += gcnew EventHandler(this, &ClassName::ItWasClicked);

The first argument to ItWasClicked would be b, the Button instance.

Not much use for core logic, but it could be for UI effects. For example:

void LightMeUp(Object^ sender, EventArgs^ a)
{
Control^ c = dynamic_cast<Control^>(sender); // C# "as" operator
if (c != nullptr) {
c->BackColor = Color::Yellow;
}
}

EventHandler^ eIn = gcnew EventHandler(this, &ClassName::LightMeUp);
for each (Control^ c in Controls) {
c->GotFocus += eIn;
c->MouseEnter += eIn;
}
Oct 8 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

54
by: Brandon J. Van Every | last post by:
I'm realizing I didn't frame my question well. What's ***TOTALLY COMPELLING*** about Ruby over Python? What makes you jump up in your chair and scream "Wow! Ruby has *that*? That is SO...
92
by: Reed L. O'Brien | last post by:
I see rotor was removed for 2.4 and the docs say use an AES module provided separately... Is there a standard module that works alike or an AES module that works alike but with better encryption?...
3
by: Steven T. Hatton | last post by:
I stumbled upon this blog while googling for something. I have to say, I really don't understand what Lippman is trying to tell me here. I included the first paragraph for context, but the second...
6
by: Graham Pengelly | last post by:
Hi I'll try to spell out my problem as succinctly as possible... My database has a User table, an Organisation table, a Department table and a JobType table (amongst others) The...
0
by: TT (Tom Tempelaere) | last post by:
Hi, In my project I have a seperate logging application. I use remoting to log to it. The remoted object exposes a certain (log-)interface, and the methods therein are all OneWay methods...
4
by: Rachel Suddeth | last post by:
What is the difference between a managed/unmanaged resource, and how do you tell which is which? I'm trying to understand how to write some Dispose() methods, and we are supposed to put code that...
167
by: darren | last post by:
Hi I have to write a multi-threaded program. I decided to take an OO approach to it. I had the idea to wrap up all of the thread functions in a mix-in class called Threadable. Then when an...
14
by: Jack | last post by:
Hi, I meet a question with it , I did not get clear the different betteen them, for example: #include <iostream>
9
by: xiao | last post by:
It always dumped when I tried to run it... But it compiles OK. What I want to do is to do a test: Read information from a .dat file and then write it to another file. The original DAT file is...
275
by: Astley Le Jasper | last post by:
Sorry for the numpty question ... How do you find the reference name of an object? So if i have this bob = modulename.objectname() how do i find that the name is 'bob'
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
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,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.