Board index » delphi » Sender object

Sender object

how do i access the properties of sender.  eg, first i want test sender to
determine the class, eg TDBCombobox, then, if tests okay, then get and set
the text property.  i want to do this because i have multiple components
using the same function.  i don't want to repeat the function for each
component...

thanks.

 

Re:Sender object


Quote
> determine the class, eg TDBCombobox, then, if tests okay, then get and set

if (Sender is TDBCombobox) then
begin

Quote
> the text property.  i want to do this because i have multiple components

  (Sender as TDBCombobox).Text;
// safer typecasting
end;

Quote
> thanks.

No Problem

Lynear

Re:Sender object


"Dan" said:

Quote
> if (Sender is TDBCombobox) then
> begin
>   (Sender as TDBCombobox).Text;
> // safer typecasting
> end;

It's not safer and it's a waste of time.  You only need to use 'as' when
you haven't done an 'is' before hand.  This is not your case.

Vik

Re:Sender object


"Gregg R. Zegarelli" <i...@ziata.com> wrote in message
news:3b436a3c$1_1@dnews...

Quote
> how do i access the properties of sender.  eg, first i want test sender to
> determine the class, eg TDBCombobox, then, if tests okay, then get and set
> the text property.  i want to do this because i have multiple components
> using the same function.  i don't want to repeat the function for each
> component...

Depending on what tests you need to do to sender this maybe applicable, ie
the Text property of Sender must be a published property

if IsPublishedProp(Sender,'Text') and PropIsType(Sender,'Text',tkLString)
then SetStrProp(Sender,'Text',yourTextValue);

Re:Sender object


Quote
"andrew" <and...@there.com> wrote in message news:3b43a4d6_1@dnews...
> if IsPublishedProp(Sender,'Text') and PropIsType(Sender,'Text',tkLString)
> then SetStrProp(Sender,'Text',yourTextValue);

and you have to include the unit TypInfo in your uses clause

andrew

Re:Sender object


Quote
On Wed, 4 Jul 2001 21:58:50 +0200, Vik (Supinfo) <v...@noos.fr> wrote:
>"Dan" said:
>> if (Sender is TDBCombobox) then
>> begin
>>   (Sender as TDBCombobox).Text;
>> // safer typecasting
>> end;

>It's not safer and it's a waste of time.  You only need to use 'as' when
>you haven't done an 'is' before hand.  This is not your case.

I agree..you already know it is..

If (Sender Is TDBComboBox) Then
  TDBComboBox(Sender).Text = //

..seems cleaner to me.

John McTaggart

Other Threads