Solved

Sender: TObject

Posted on 2002-03-20
6
897 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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi - replicating a form 8 86
error 1.1 400 Bad request idhttp delphi 18 153
LAN or WAN ? 11 96
Embarcadero C++ builder XE10.1 Berlin find In files dialogue stunted display 4 56
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

820 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