• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 300
  • Last Modified:

How control TImage loading/unloading?

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 := 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
  • 2
1 Solution
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...
DippenAuthor Commented:
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:


and if the file does exist I use LoadFromFile and BringToFront instead.
If you already have the shape, then that is probably easier.

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now