BitBlt and TBitmap in Delphi 2.0

Quote
>Richard G Coleman <rich...@alchemedia.co.uk> wrote:

>>I am creating a program in Delphi 1 (16 bit), and one part of it
>>includes a slideshow of full screen(640 * 480) bitmaps.  I have come up
>>against a problem, though, in that the way I have done it so far, I am
>>using a separate form for each graphic.  The problem with this is that I
>>can see a noticable delay (1 second or so) between the form becoming
>>visible and the graphic appearing.  All I see at first is a grey
>>background.

>The delay you're seeing is the time it takes to create a real bitmap
>handle from BMP file data in memory.  To conserve Windows GDI
>resources and improve form load times, the TBitmap class doesn't
>create a real bitmap handle until it's absolutely necessary - in this
>case, the bitmap handle isn't required until the image control is told
>to paint itself.

>To force the bitmap to create the handle sooner, simply touch (read
>from) the bitmap's handle property.  Do this before making the form
>visible and the delay between when the form pops up and when the image
>is draw will disappear.

>-Danny
>==============
> Danny Thorpe
> author of "Delphi Component Design" 1996 Addison Wesley
> ISBN 0-201-46136-6
>==============

Danny,

Your reply of last October 31 to Richard Coleman saved me from
converting my Delphi 2.0 project to Visual Basic...

Inside a single form, these lines work:

    Bmp := TBitmap.Create;
    Bmp.LoadFromFile( ...some bmp file... );
    BitBlt( Canvas.Handle, 0, 0, Bmp.Width, Bmp.Height,
            Bmp.Canvas.Handle, 0, 0, SRCCOPY );

But when the first 2 lines are included in a class which also
contains a reference to the form where the bit blitting is
targeted, nothing is drawned...!??!

If, in that class, and after the "LoadFromFile()" instruction,
I insert the following dummy instruction:

    S{*word*99} := Bmp.Handle;

...then everything works fine!

The purpose of that class is for drawing multiple animated
sprites with a moving background and is now quite complex.
Everything works quite fine under VB4 (32 bits) but Delphi
was in need in my case to encapsulate and "object-orient"
a little more that monster. As well as for the increased
speed, needless to say...

As I do not have the VCL source, that
"S{*word*99} := Bmp.Handle" behaviour is strange to me...

Guessing, as a writer, that you have the "Delphi 2 Developer's
Guide" from Xavier Pacheco and Steve Teixeira, you should
look at page 291 for a sample of that "bit blitting" with
TBitmap objects. Why their code works? No apparent "Bmp.Handle"
stuff reading appears in their Animation Project's main form !

I may understand your explanation to Richard Coleman, but
depending of where that "Bmp" is instanciated and how the
form is referenced makes difference. Why?

Thanks for any advice...!

Gilles Racine

e-mail:  digit...@aei.ca