Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 4 of 4 total
Thread EWB 2 - Trying to change the background color temporarily
Sun, May 17 2015 4:51 PMPermanent Link

David Martin

I would like to change the background color of a panel for 2 seconds before reverting back to the original color. The code I have used does not work and I have traced it to behavior demonstrated in the following code:


  BasicPanel1.Background.Fill.Color:=clOrange;
  Timer(2); // Pause for 2 seconds--this works and is not the problem
  ShowMessage('The color of the panel should have changed to orange by now, but it has not changed yet.');

The color of the panel changes to orange after the ShowMessage dialog is closed. How can I get the color to change before the Timer function is called?

Thanks for any help.

David Martin
Sun, May 17 2015 7:11 PMPermanent Link

Raul

Team Elevate Team Elevate

On 5/17/2015 4:51 PM, David Martin wrote:

>     Timer(2); // Pause for 2 seconds--this works and is not the problem

What does this do actually ?!

Are you blocking the execution by looping or such? If so then likely no
repaint takes place.

> The color of the panel changes to orange after the ShowMessage dialog is closed. How can I get the color to change before the Timer function is called?

i would suggest you use an actual timer for this.


....
prevColor := BasicPanel1.Background.Fill.Color;
BasicPanel1.Background.Fill.Color := clOrange;
Timer1.Interval := 2000;
Timer1.Enabled := true;

....


procedure TForm1.Timer1Timer(Sender: TObject);
begin
  Timer1.Enabled := false;
  BasicPanel1.Background.Fill.Color := prevColor;
end;

....


Raul
Sun, May 17 2015 8:38 PMPermanent Link

David Martin

Raul wrote:

>>     Timer(2); // Pause for 2 seconds--this works and is not the problem

>What does this do actually ?!

As you surmised, this executes a dummy while loop for 2 seconds. I was not aware of the non-visual TTimer component that is on the System tab in the IDE. I followed your lead and was able to get the behavior I was looking for. Thank you!

DM
Mon, May 18 2015 4:00 AMPermanent Link

Matthew Jones

David Martin wrote:

>  and was able to get the behavior I was looking for

If you want to get fancy, check out the animation capabilities. I have
a TPanel behind one button which I fade in and out to gentle bring
attention to it.

--

Matthew Jones
Image