Solved

Sender: TObject

Posted on 2002-03-20
6
898 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
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…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

737 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