Mega Search
23.2 Million


Sign Up

Make a donation  
How to access properties of component calling the function?  
News Group: embarcadero.public.cppbuilder.language.cpp

Is there a way to access the properties of the function or component that in calling the current function?  

Here is a simple example of what I have done

void __fastcall TForm1::AdvSmoothButton1MouseEnter(TObject *Sender)
{

	AdvSmoothButton1->Appearance->GlowPercentage = AdvSmoothButton1->Appearance->GlowPercentage + 15;

}

This works great for that one button, but I would like to write this function so that it will modify the properties of the any button that calls it.  I don't want to write this same code for a 100 or so different buttons.  

I have been trying to figure out how to access the handle or pointer that is calling this function through (TObject *Sender) either I just simply haven't stumbled on the solution or that is a dead end.  Can anyone point me in the right direction.  Thanks for your help.

Vote for best question.
Score: 0  # Vote:  0
Date Posted: 19-Dec-2014, at 1:14 PM EST
From: Erik McClain
 
Re: How to access properties of component calling the functi  
News Group: embarcadero.public.cppbuilder.language.cpp
> {quote:title=Remy Lebeau (TeamB) wrote:}{quote}
> Erik wrote:
> 
> > Is there a way to access the properties of the function or component
> > that in calling the current function?
> 
> The event's Sender parameter points to the component instance that is triggering 
> the event.  Simply type-cast that pointer to the appropriate type, eg:
> 
> {code}
> void __fastcall TForm1::AdvSmoothButton1MouseEnter(TObject *Sender)
> {
>     TAdvSmoothButton *btn = static_cast(Sender);
>     btn->Appearance->GlowPercentage = btn->Appearance->GlowPercentage + 15;
> }
> {code}
> 
> --
> Remy Lebeau (TeamB)


Thanks a lot.  I knew there had to be a simple solution, I searched hours trying to find it with no avail.  I had to tweak it to static_cast(Sender);  Other then that its perfect! Thanks again.

Vote for best answer.
Score: 0  # Vote:  0
Date Posted: 22-Dec-2014, at 5:34 AM EST
From: Erik McClain
 
Re: How to access properties of component calling the functi  
News Group: embarcadero.public.cppbuilder.language.cpp
Erik wrote:

> Is there a way to access the properties of the function or component
> that in calling the current function?

The event's Sender parameter points to the component instance that is triggering 
the event.  Simply type-cast that pointer to the appropriate type, eg:

{code}
void __fastcall TForm1::AdvSmoothButton1MouseEnter(TObject *Sender)
{
    TAdvSmoothButton *btn = static_cast(Sender);
    btn->Appearance->GlowPercentage = btn->Appearance->GlowPercentage + 15;
}
{code}

--
Remy Lebeau (TeamB)

Vote for best answer.
Score: 0  # Vote:  0
Date Posted: 19-Dec-2014, at 1:31 PM EST
From: Remy Lebeau (TeamB)