I would like to create a function which replaces the current image with another one. The problem is that I have 64 pictures to replace. I created a function with a TImage* Sender parameter but it works only when I set Sender as TObject* instead.
How can I change this function:
void __fastcall TForm1::Image1Click(TObject *Sender)
{
Sender->Picture->LoadFromFile("puste.bmp");
}
into this
void __fastcall TForm1::Image1Click(TImage *Sender)
{
Sender->Picture->LoadFromFile("puste.bmp");
}
I am using the VCL library.
You can't change the signature of the event handler. It has to be what the VCL expects it to be, which in this case is defined by the
TNotifyEventtype, which is what theOnClickevent is declared as:However, you don't need to change the signature. All VCL components derive from
TObject, and theSenderparameter points to the control that was clicked on. So, in this case, you can simply use a type-cast to access functionality that is specific toTImage, eg:You can then assign this 1 handler to all 64 of your
TImagecontrols.If you need to differentiate between different
TImagecontrols, you can use theTImage'sNameorTagproperty for that purpose.