Here is my code to "animate" the TPanel
when the mouse cursor is hovered over it. I also have a code block to unanimate it.
procedure Tmain.pStarting1MouseEnter(Sender: TObject);
begin
if sender = pStarting1 then pStarting1.BevelInner := bvLowered;
if sender = pStarting2 then pStarting2.BevelInner := bvLowered;
if sender = pStarting3 then pStarting3.BevelInner := bvLowered;
if sender = pStarting4 then pStarting4.BevelInner := bvLowered;
if sender = pStarting5 then pStarting5.BevelInner := bvLowered;
if sender = pStarting6 then pStarting6.BevelInner := bvLowered;
if sender = pStarting7 then pStarting7.BevelInner := bvLowered;
if sender = pStarting8 then pStarting8.BevelInner := bvLowered;
if sender = pStarting9 then pStarting9.BevelInner := bvLowered;
end;
As you can see, its very repetitious and since I have another 27 TPanel
s to animate, that would mean another 27 lines of repetitious code. So is there a way I can optimise this?
I have also tried placing that block of code into a separate procedure (in the same unit). but Delphi tells me that sender
is undeclared.
if Sender is TPanel then
TPanel(Sender).BevelInner := bvLowered;
or, if you are certain that Sender
is always a TPanel
, simply
(Sender as TPanel).BevelInner := bvLowered;
or (if you are really certain)
TPanel(Sender).BevelInner := bvLowered;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With