Solved

how to use a resource file

Posted on 1998-11-11
7
174 Views
Last Modified: 2010-04-04
I've created an object that uses a lot of small bitmaps and resources.

I used to load a file whenever I needed it, but this takes too long and a file gets loaded everytime I want to display a bitmap or play a wave file.

I put these files in a resource file and have created and compiled a .res file. I'm now looking for a way to load these files into memory and use them from there on without having to reload it everytime. I think I can use streams for this, but I'm not sure what exactly they are and how I can use them.

Can someone explain to me how to load wave and bitmap files from a resource into memory and then load them from memory into a tbitmap and play the sound using PlaySound as much as I want to without having to reload it?

Thanks,
Michael
0
Comment
Question by:michaelsanders
7 Comments
 
LVL 3

Expert Comment

by:philipleighs
ID: 1346587
The easiest way is to put a TImage on your form, set the picture property and make it invisible.
You can draw it onto the form canvas by:

Canvas.Draw(50, 50, Image1.Picture);

The bitmap is part of the exe, and is loaded when the form is created.
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1346588
Here is how....

Once way to do that is to create a bitmap and load it at run-tim as follows.,..

//Gloabal Var...

var
  b : TBitmap;

OnCreate()
b := TBitmap.Create;
b.loadfromfile(Filename);

OnPaint() //Or somewhere else...wherever you want to draw it...
Canvas.Draw(x,y, b);

OnDestroy()
b.Free;
--------------
The other way by using resource file is as follows...

Use the LoadBitmap(hInstance, 'MYBITMAP'); To load a bitmap from a resource file...

Cheers,
Viktor
0
 
LVL 1

Author Comment

by:michaelsanders
ID: 1346589
I can't use the loadfromfile since that was what I was doing before...
I could use loadbitmap to load a bitmap from my resource file, but how would I deal with the wave file?
I don't want to put lots of tbitmaps in my object either, since most of them will not be used everytime the program runs this would be to much overkill.

0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 4

Accepted Solution

by:
BoRiS earned 100 total points
ID: 1346590
michealsanders

Viktornetr is right again :-) to load the bitmap from resource use

LoadBitmap(hInstance, 'MYBITMAP');

To play a wav file from the resource use

PlaySound('NameOf WavFileHere', Hinstance, SND_RESOURCE or SND_SYNC);
The name is from the name you gave it in the .res file

Remember to add mmsystem to your uses clause...
uses
Windows, Forms,..., mmSystem;
And the .res file is added to your app that contains the wavs...
{&R yourres.res}

Later
BoRiS

0
 
LVL 10

Expert Comment

by:viktornet
ID: 1346591
Well, that's what I said but no one listens to me...
0
 
LVL 4

Expert Comment

by:BoRiS
ID: 1346592
viktornet

Now now :-)

Later
BoRiS
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1346593
:)
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
update joined tables 2 55
Delphi: barcode reading on android platform 1 51
MS Access from Delphi 31 61
firemonkey Android Listview Sort items 7 53
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question