4

There's a TImage component on a form in my program.

In some situation, the program must test:

If "there is an image assigned to the picture property of the TImage component" then ...

How can I do this?

Gabriel
  • 20,797
  • 27
  • 159
  • 293
Raphael
  • 51
  • 1
  • 4

3 Answers3

3
if Image1.Picture.Graphic = NIL 
then ShowMessage("There is no image.")
else ShowMessage("Image found.");

If working with bitmaps, you can also do this:

if Image.Picture.Bitmap.Empty then ShowMessage("There is no spoon");
Gabriel
  • 20,797
  • 27
  • 159
  • 293
  • 1
    `if NOT Image.Picture.Empty then DoStuff` as the OP asked to run `DoStuff`only when there's a picture. – Fabricio Araujo Jul 13 '11 at 21:11
  • 2
    @FabricioAraujo - I just supposed that the OP knows how to adjust the code (use a negation) to adapt it for its needs :) – Gabriel Apr 09 '19 at 11:12
2

Better late than never!
The right way is:

if Assigned(Image1.Picture.Graphic) then ...

Xalo
  • 164
  • 1
  • 2
  • 13
0

You don't say, but I'll assume you're talking about Delphi.

You can check whether there's a bitmap in the TImage control by testing:

if Image.Picture.Bitmap.Width > 0 then
  // do whatever
Rob McDonell
  • 1,309
  • 9
  • 15
  • I think that testing for the presence of the object itself is better than testing for one of the properties of that object. – Gabriel Apr 09 '19 at 11:07