tags:

views:

34

answers:

2

Hi,

sorry for my bad english :D

I have this piece of code:

TShape* T[256];

/* Other code ... */

for (int i = 255; i > 0; i--) {
     T[i]->Brush->Color = T[i - 1]->Brush->Color;
     T[i]->Pen->Color = T[i - 1]->Pen->Color;
};

The cycle is executed by a TTimer each 100 milliseconds and the Color of the first TShape change each 100 milliseconds.

During this cycle, I see a blinking white horizontal lines, because before to receive the color of the other TShape, each TShape is invalidated and becomes white.

Is there a way to avoid this behaviour? Maybe, I must override some method?

Thanks

A: 

I think double buffering is the key to your problem. If you are using C++Builder 2009 or newer probably setting property Controls::TWinControl::DoubleBuffered for your current frame will be enough.

jszpilewski
I use C++ Builder 6 :(
Midnightmare
TWinControl has a DoubleBuffered propety in BCB 6. jszpilewskiis referring to you setting DoubleBuffered=true on whatever Parent control you have placed your TShape objects on.
Remy Lebeau - TeamB
With DoubleBuffered = true applied at TForm I have resolved the problem!Thanks at all!
Midnightmare
A: 

TShape invalidates itself every time you change its Brush and Pen properties, so your loop is double-invalidating each TShape. As a workaround, try temporarily removing the OnChange event handlers that TShape assigns internally, and then Invalidate() the TShape only once after you have finished updating it. For example:

for (int i = 255; i > 0; i--)
{ 
    TNotifyEvent OldBrushChange = T[i]->Brush->OnChange;
    T[i]->Brush->OnChange = NULL;

    TNotifyEvent OldPenChange = T[i]->Pen->OnChange;
    T[i]->Pen->OnChange = NULL;

    T[i]->Brush->Color = T[i - 1]->Brush->Color; 
    T[i]->Pen->Color = T[i - 1]->Pen->Color; 

    T[i]->Brush->OnChange = OldBrushChange;
    T[i]->Pen->OnChange = OldPenChange;
    T[i]->Invalidate();
}; 
Remy Lebeau - TeamB
With this workaround the blinking is worse!
Midnightmare