Solved

How control TImage loading/unloading?

Posted on 1997-05-04
3
273 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

825 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