Solved

How control TImage loading/unloading?

Posted on 1997-05-04
3
282 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
When I am typing into a TEdit last word repeats 7 162
Making delphi communicate with a c# service 16 124
Firemonkey webbrowser scrollbars ? 1 57
DBGrid or StringGrid ? 6 120
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…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

726 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