Board index » delphi » Question about Delphi "Sender"

Question about Delphi "Sender"

        I everyone,

                I wonder if anyone can help me...  I'm programming a
calculator for an homework.  I'm trying to attach a procedure to 11 buttons.  
I have to use the Sender parameter but I don't know how to use it...

Edit1.Text := Sender.Caption;

What is wrong with that???

        Reply by E-Mail please...

                        Guillaume Boudreau
                        s1067...@aix2.uottawa.ca

 

Re:Question about Delphi "Sender"


Quote
> What is wrong with that???

Sender is TObject which doesnt have a caption.  
You must typecast it

 _
| | |  _     _        http://www.stud.ntnu.no/~olavb/
|_| |_|_|_|_|                     mailto:Ol...@dds.nl
Eyecom Images, Amsterdam

Re:Question about Delphi "Sender"


Guillaume

You have to tell the compiler what type Sender is because
as far as it knows Sender is a TObject and doesn't have
a caption property

eg

if Sender is TButton
then with Sender As TButton do
  Edit1.Text := Sender.Caption;

Or as one line

Edit1.Text := TButton(Sender).Caption;  // TButton() is a typecast

HTH

Clint.

Re:Question about Delphi "Sender"


Quote
s1067...@aix2.uottawa.ca (Guillaume Boudreau) wrote:

Hi Guillaume,

Quote
>            I wonder if anyone can help me...  I'm programming a
>calculator for an homework.  I'm trying to attach a procedure to 11 buttons.  
>I have to use the Sender parameter but I don't know how to use it...
>Edit1.Text := Sender.Caption;

Well, I had the same problem when I started programming in Delphi...
You have to explain Delphi, what type of Sender is. If the procedure
is called by Buttons (TButton), Sender will be TButton. Delphi doesn't
know this, so you have to do the following:

Edit1.Text := (Sender as TButton).Caption;

Quote
>    Reply by E-Mail please...

ok,,, I'll do so too :-)

bye...
Alexander

      [Replys Cc as email please!]

---
Alexander Lucke,
Email: <a...@next2.psychologie.hu-berlin.de>
WWW: <http://141.20.111.4/al/>

Other Threads