tags:

views:

276

answers:

3
+3  Q: 

stop flickering

hi all

I have an old program written in borland pascal and in Delphi if I use the Form1.Canvas.LineTo and MoveTo functions I get a flickering effect. Can anyone tell me how to get rid of the flickering?

thanks

+4  A: 

A general technique for reducing flicker in animated graphics operations is called double buffering. The idea is that you do all drawing to an offscreen bitmap, then when you've finished rendering the whole scene, copy the entire bitmap to the visible display.

The term also relates to hardware-supported techniques such as the ability to exchange the whole video display buffer with an alternate one, which is used in dedicated systems like console video games.

Greg Hewgill
+13  A: 

Try to set DoubleBuffered to true in Form.OnCreate.

winSharp93
When I was a young lad, we had to implement double buffering ourselves. Uphill both ways, in the snow!
Greg Hewgill
@Greg: OTOH this has been supported by the Delphi VCL for more than 10 years now, so there's actually little incentive to rough it. +1 for this answer, it's the Delphi way of doing double-buffering.
mghie
@Greg: Barefoot?
HMcG
@Greg: By candlelight?
cjrh
A: 

Although using double buffering is usually the best solution, it is not always the right solution, and definitely not the most memory saving solution. However if you only draw a part of the image, I'd go with that solution as well setting DoubleBuffered to true as mentioned in the other comments.

However if you fill the entire components area every time you draw anyway, you might want to choose a different approach. If you set the ComponentStyle to csOpaque you'll avoid having the component erase the background, and thereby removing a source of the flickering, without having to double buffer. This of course requires you to draw on the entire component area, so the solution is only really suitable if you do.

In general however if memory consumption is of no importance, I'd go for the double buffering as well, I just wanted to supply you with an alternative. :)

TommyA