Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

how to use a resource file

Posted on 1998-11-11
7
Medium Priority
?
178 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 4

Accepted Solution

by:
BoRiS earned 300 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…

876 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