开发者

Delphi 7 -> Unable Loading an Image from a Resource file

I've been looking hours over the net, using Google, trying for PDF's and still unable to load an Image resource in Delphi 7..

My test.rc file goes like this:

1 RT_BITMAP "1.bmp"

I've added the test.rc file to 开发者_StackOverflow中文版my project using Project->Add to Project.. which compiled a test.res file upon build and seems to have automatically included the .res file into my project (because using the {$R test.res} would say I already use that resource). I also tried removing the test.res from the project using Project->Remove from Project.. and manually adding the {$R test.res} to my project.

However no matter how I include the test.res file.. I get the

Project Project2.exe raised exception class EAccessViolation with message 'Access violation at address 00408D0C in module 'Project2.exe'. Read of address 00000001'. Process stopped. Use Step or Run to continue.

at First I used

Image1.Picture.Bitmap.LoadFromResourceID(hInstance,1);

Because this is what I found using Google. And I got this error. Later I tried

procedure TForm1.Image1Click(Sender: TObject);
var bBitmap : TBitmap;
begin

 bBitmap := TBitmap.Create;
 try

  bBitmap.Handle := LoadBitmap(hInstance, '1');
  Image1.Width := bBitmap.Width;
  Image1.Height := bBitmap.Height;
  Image1.Canvas.Draw(0,0,bBitmap);
 finally

  bBitmap.Free;
end;


end;

This didn't get me any errors, and nither did it show the image so the problem remains unsolved..

I'm a newbie to the use of Resources but I must load some images into resources before I release my project so the .BMP files won't be tempered with...

any help would be highly appreciated!


I reproduced exactly your same problem in a test program.

I then changed RT_BITMAP to BITMAP, recompiled RC and tested.

It works.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜