PDA

View Full Version : Loading a bitmap from a resource



Useless Hacker
11-03-2003, 07:58 PM
I am trying to load a 256-colour bitmap into a TImage component from a resource. This is my code:
Image.Picture.Bitmap.LoadFromResourceName(HInstanc e, 'MYBITMAP');
However, this raises an EResNotFound exception. I have checked that my application has {$R *.res}, and there most definately is a bitmap called 'MYBITMAP'. Can anyone see what could be going wrong?

Xorcist
12-03-2003, 02:02 AM
Dont' use {$R *.RES}, use {$R ResourceFileName.res}. Don't ask me why, it's some kinda bug or something. But using the exact filename seems to remedy the problem.

Alimonster
13-03-2003, 01:30 PM
Sorry to ask this, but are you sure that you've included the resource file properly?

Bear in mind that *.res includes a resource file with the same filename, but different extension, to the current unit. In other words, if your unit is "my_unit" then it would include "my_unit.res". It doesn't include every resource file in the directory, as you might have thought...

Useless Hacker
13-03-2003, 02:30 PM
The resource file is just the application resource file, as in the one included in the project source file (.dpr). I guess I could try putting it in a separate resource file for that unit.