Solved

how to use a resource file

Posted on 1998-11-11
7
170 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

746 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now