Delphi 7 & # 8594; Unable to load image from resource file

I watched the clock over the net using Google, trying in PDF and still cannot download the image resource in Delphi 7 ..

My test.rc file looks like this:

1 RT_BITMAP "1.bmp" 

I added the test.rc file to my project using Project-> Add to project .. which compiled test.res > file on build and seems to automatically include the .res file in my project (since using {$ R test.res } says that I already use this resource), I also tried to remove test.res from the project using Project-> Remove from Project .. and manually add {$ R test.res} to my project.

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

Project Project2.exe added exception class EAccessViolation with the message "Access violation at address 00408D0C in the module Project2.exe. Read address 00000001 '. The process is stopped. To continue, use Step or Run.

I used first

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

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

 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 did not cause me errors, and did not show the image, so the problem remains unresolved.

I am new to using resources, but before uploading my project I have to upload some images to resources, so .BMP files will not be tempered ...

Any help would be greatly appreciated!

+4
source share
1 answer

I reproduced exactly the same problem in a test program.

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

He works.

+7
source

All Articles