Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2013-11

Resources

3 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Donald Ziesig

Hi All!

I have been trying to use a resource file (mydata.rc) to include some bitmap images in an app but with no success. For simplicity, I have pared the rc file to a single line:

pix2 BITMAP "/home/mydir/Desktop/myapp/2.bmp"

I have the following lines in my main unit:

{$R *.lfm} // the original
{$R mydata.rc}

mydata.rc is being compiled. It generates lib/x86_64-linux/mydata.res as expected.

I can see the following in the compiled lib/x86_64-linux/mydata.res file using od

B nul I nul T nul M nul A nul P nul

and

P nul I nul X nul 2 nul

followed by the header of a bitmap image, so I am pretty sure that the resource compiler (windres) is working correctly.

When I try to load the bitmap using:

   Image1.Picture.LoadFromLazarusResource('PIX2');  // Tried 'pix2' as well

I constantly get Resource "pix2" not found.

I put some diagnostics in LResources.pp and I can see other resources being found, and pix2 being sought but it never finds a resource from the mydata.res file.

It appears that whatever (I'm guessing here) has to be done to include the resources from mydata.res into the executable is not happening.

I am using Lazarus V 1.1, and FPC V 2.6.2

Can anyone point me in the right direction?

Thanks,

Don Ziesig

P.S. I started with PNG graphics and ended up with BMP only because that seemed to be the least common denominator in the all of the docs I could find.

Reply by email

Sven Barth
to Donald Ziesig: Hi All! I have been trying to use a resource file (mydata.rc) to include some bitmap…
Donald Ziesig wrote
Image1.Picture.LoadFromLazarusResource('PIX2'); // Tried 'pix2' as well

Lazarus Resources FPC Resources

Lazarus Resources where the resources that were used before FPC supported resources itself. So kick out the LResources unit and change the call to:

=== code begin ===

res := TResourceStream.Create(HInstance, 'PIX2', 'BITMAP');
try
   Image1.Picture.LoadFromStream(res);
finally
   res.Free;
end;

=== code end ===

If you know the file extension (e.g. you don't allow the users to put in a PNG resource while your default one is a BMP resource) you could also use LoadFromStreamWithFileExt instead.

Regards,
Sven

Reply by email