Solved

How control TImage loading/unloading?

Posted on 1997-05-04
3
261 Views
Last Modified: 2010-04-06
I think this is a simple one:

I am developing a small database application (not using BDE, but record ... end;) A TImage component is placed on the main form and when it's time to update the current record a certain image should be read from disk using LoadFromFile. The filename of the picture is built from the information in the database and can not be altered.

   Now, here's the question: If the file that is requested can not be found on disk (perfectly alright), how should I proceed? The TImage component should then be blank instead, but at the next update it should be able to contain a new picture. Should I solve it like this:

Image1.Picture.Free;
Image1.Picture := Nil;

or just like this:

Image1.Picture := Nil;

   If I free the Picture property, can I safely use LoadFromFile again when it's time to show another picture?
   If I just set the Picture property to Nil, does the LoadFromFile method use the same allocated memory the next time or does it allocate new memory since I didn't free the old chunk?

If I have not made myself clear, please tell me and I will explain it further. I consider this a very easy question, but I'm having some problem expressing myself since English's not my native language... ;-)

Thanks for your help.

Daniel, Malmoe, Sweden
0
Comment
Question by:Dippen
  • 2
3 Comments
 
LVL 2

Accepted Solution

by:
gysbert1 earned 50 total points
ID: 1335898
How about using the FillRect method, and filling it with a blank rectangle of size Image.Width by Image.Height? That way the TImage component is never destroyed, and the picture is blank...
0
 

Author Comment

by:Dippen
ID: 1335899
That sounds alright. I already have a white rectangular shape (as background) behind the picture. Wouldn't the easiest thing to do then to just check if the BMP-file exists. If it doesn't I use:

Image1.SendtoBack;

and if the file does exist I use LoadFromFile and BringToFront instead.
0
 
LVL 2

Expert Comment

by:gysbert1
ID: 1335900
If you already have the shape, then that is probably easier.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

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…
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…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

757 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

18 Experts available now in Live!

Get 1:1 Help Now