Posts Tagged ‘tips and tricks’

Adding resources to a Delphi app at build time

Saturday, February 28th, 2015

Just a quickie to let people know you can add resources to a Delphi app by using ‘Project->Resources and Images’ from the menu, but also by including them yourself using a .RES file that you can direct the compiler to generate during the build process. When I went looking for an answer there was some debate as to whether this was possible and if so how. There didn’t appear to be a consensus so I have just tested it with XE7 and it is possible using a resource directive in a unit.

So, with this resource directive in a unit:-

{$R sample.res sample.rc}

sample.rc contains:-

MYPNG RCDATA sample.png

And I can then load that image using:-

pngImage.loadFromResourceName(HINSTANCE,'MYPNG');

I know it works and loads correctly because I went on to paint the image on a canvas on the form.

Bad Behavior has blocked 103 access attempts in the last 7 days.

communication