Daniel Grillo
Daniel Grillo

Reputation: 2418

Problem to load from ID of a resource file in Delphi

When I use the method LoadFromResourceName(HInstance, 'PNGImage0') it works, but when I use LoadFromResourceID(Hinstance, 0) don't. It returns me an exception EResNotFound with message 'Resource 0 not found'.

I'd like to know what's the problem?

Edit

My RC File:

PNGImage0 RCDATA "Image0.png"
PNGImage1 RCDATA "Image1.png"
PNGImage2 RCDATA "Image2.png"
PNGImage3 RCDATA "Image3.png"
PNGImage4 RCDATA "Image4.png"
PNGImage5 RCDATA "Image5.png"
PNGImage6 RCDATA "Image6.png"

Upvotes: 0

Views: 2396

Answers (1)

Uli Gerhardt
Uli Gerhardt

Reputation: 14001

AFAIK a resource is identified either by name or by ID. You probably have an resource script (*.rc) that identifies the image by name like

PNGImage0 RCDATA "FileName.png"

where PNGImage0 is not defined as a number.

To define PNGImage0 as a number, just have

const
  PNGImage0 = 1;

in a unit (say YourResDefines.pas) and put #include "YourResDefines.pas" at the top of the *.rc file. Then you have to use LoadFromResourceID(HInstance, PNGImage0) without the single quotes.

Upvotes: 2

Related Questions