Solved

Sender: TObject

Posted on 2002-03-20
6
902 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
Independent Software Vendors: 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

Enroll in June's Course of the Month

June’s Course of the Month is now available! Experts Exchange’s Premium Members, Team Accounts, and Qualified Experts have access to a complimentary course each month as part of their membership—an extra way to sharpen your skills and increase training.

Question has a verified solution.

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

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…
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…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

691 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