Solved

Sender: TObject

Posted on 2002-03-20
6
888 Views
Last Modified: 2008-02-01
How can I use the Sender object in my app ?

example:

procedure TfrmClients.cbNoClientsClick(Sender: TObject);
begin
with Sender do
  begin
  //doStuffWithSender
  end;
end;


I want to use the methods and properties of Sender but I can't manage to tell my app what Sender is actually.  Is there any way to tell my app that the Sender is a button or a combobox or something ?

Thanks!!
0
Comment
Question by:qas
6 Comments
 
LVL 15

Accepted Solution

by:
simonet earned 100 total points
ID: 6883005

Without having to resort to RTTI (which is a pain in the butt), you kinda have to do some guesswork:

procedure TfrmClients.cbNoClientsClick(Sender: TObject);
begin
  if Sender is TButton then
    with TButton(Sender) do
    begin
       // code goes here
    end;

  if Sender is TComboBox then
    with TComboBox(Sender) do
    begin
       // code goes here
    end;

  // ... and so on...
end;

Yours,

Alex
0
 
LVL 44

Expert Comment

by:CrazyOne
ID: 6883048
Yeah I agree with Alex. You would need to specifically Identify the actual object being passed in your parameter. :>(
0
 

Author Comment

by:qas
ID: 6883084
Perfect!
Exacly what I needed.
I actually knew what the component was.  I just didn't kow how to tell the app.

Thanks!
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 1

Expert Comment

by:rchambel
ID: 6883106
You may try this one:

 if Sender.ClassName='TButton' then ...
 if Sender.ClassName='TEdit' then ...


Of course you're gonna have a lot of work. it only depends on wich objects directly call that method.

Hope you like this approach :-)

Best regards
0
 
LVL 1

Expert Comment

by:rchambel
ID: 6883109
You may try this one:

 if Sender.ClassName='TButton' then ...
 if Sender.ClassName='TEdit' then ...


Of course you're gonna have a lot of work. it only depends on wich objects directly call that method.

Hope you like this approach :-)

Best regards
0
 
LVL 1

Expert Comment

by:rchambel
ID: 6883150
Sorry for the "double" comment... this thing got stucked!

I knew simonet's solution, but didn't remember it... give him the points! :-)
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now