DoubleBuffering - Have I used it correctly?



Hi everyone,

I was hoping someone might be able to tell me if I've used the
doublebuffered property correctly in my code?

I've got a program that cycles through displaying 1 of 4 images (just
200x200 pixel rectangles of different colours) about 200 times. Each
rectangle is changed about once every 300ms and then a TLabel
containing a single character (3,4,6 or 7) is shown on top of the
rectangle.

To help reduce any flicker that may occur, I'm hoping that I've
implemented the doublebuffered property correctly. To further help,
I've tried to use the "off-screen bitmaps" method, as described at
delphi.about.com
(http://delphi.about.com/librar­y/bluc/text/uc052102g.htm). I haven't
noticed anything too bad so far, but would like to get another opinion
on this issue.

Thanks in advance!

The relevant code snippets are below:
------------------------------­-------

type
TExpMainWin = class(TForm)
StimLabel: TLabel;
CueImage: TImage;
...
public
{ Public declarations }
cue1, cue2, cue3, cue4: TBitmap;
end;

procedure TExpMainWin.FormCreate(Sender: TObject);
begin
StimLabel.Visible := false;
CueImage.Visible := false;
Self.DoubleBuffered := true;
LoadCues;
for i := 1 to 200 do
begin
Runtrial;
end;
....
end;

procedure TExpMainWin.LoadCues;
begin
Cue1 := TBitmap.Create;
Cue2 := TBitmap.Create; ...etc
...
cue1.LoadFromFile('images/rect­1.bmp');
cue2.LoadFromFile('images/rect­2.bmp'); .....etc
end;

procedure TExpMainWin.Runtrial;
begin
Self.CueImage.Visible := true;

...some IF statements to decide which cue(1-4) do display, below...

CueImage.Canvas.Draw(0,0,cue1)­; ...or (cue2,3 or 4)
CueImage.Top := (Self.ClientHeight div 2) - (CueImage.Height div 2);
CueImage.Left := (Self.ClientWidth div 2) - (CueImage.Width div 2);
Self.StimLabel.Visible := true;
....procedure that delays for 300ms...
Self.StimLabel.Visible := false;
Self.CueImage.Visible := false;
end;

.