Board index » delphi » a query on Resources and Bitmaps

a query on Resources and Bitmaps

I am loading bitmaps into a TPaintbox, loading the bitmap from
resources in the exe file. I am worried however about creating all
these TBitmaps without freeing them. Whenever I free the TBitmap it
causes a GPF, but am I using up GDI resources in not freeing it?

I am using the folowing function to handle loading the bitmap:

function LoadPicture(name: PChar): TBitmap;

var
   piccy: TBitmap;
   hpic: HBitmap;

begin
   {create a bitmap}
   piccy:= TBitmap.Create;
   {load the resource}
   hpic:= LoadBitMap(HInstance, name);
   {set the bitmap handle to the resource handle}
   piccy.Handle:= hpic;
   {return the bitmap}
   result:= piccy;
end;

this is called from the event handler which changes the bitmap using:

   bmp:= TBitmap.Create;
   bmp:= LoadPicture(p);
   picbox.Picture.Graphic:= bmp;

j...@bconsult.thenet.co.uk

 

Re:a query on Resources and Bitmaps


I am loading bitmaps into a TPaintbox, loading the bitmap from
resources in the exe file. I am worried however about creating all
these TBitmaps without freeing them. Whenever I free the TBitmap it
causes a GPF, but am I using up GDI resources in not freeing it?

I am using the folowing function to handle loading the bitmap:

function LoadPicture(name: PChar): TBitmap;

var
   piccy: TBitmap;
   hpic: HBitmap;

begin
   {create a bitmap}
   piccy:= TBitmap.Create;
   {load the resource}
   hpic:= LoadBitMap(HInstance, name);
   {set the bitmap handle to the resource handle}
   piccy.Handle:= hpic;
   {return the bitmap}
   result:= piccy;
end;

this is called from the event handler which changes the bitmap using:

   bmp:= TBitmap.Create;
   bmp:= LoadPicture(p);
   picbox.Picture.Graphic:= bmp;

j...@bconsult.thenet.co.uk

Re:a query on Resources and Bitmaps


Hi Julian,

please try this:

{$R MYPROG.RES}     {This resource contains a 'ball' bitmap}

var
  Bitmap1: TBitmap;
begin
  Bitmap1 := TBitmap.Create;
  Bitmap1.LoadFromResourceName(HInstance, 'ball');
  PaintBox1.Canvas.Draw(0, 0, Bitmap1);
  Bitmap1.Free;
end;

Ciao, Walter
--
If you like to email me please remove the 'x'

Other Threads