简体   繁体   English

如何测试TImage是否分配了图形?

[英]How to test if a TImage has a graphic assigned to it?

There's a TImage component on a form in my program. 我的程序中的表单上有一个TImage组件。

In some situation, the program must test: 在某些情况下,程序必须测试:

If "there is an image assigned to the picture property of the TImage component" then ... 如果“有一个图像分配给TImage组件的图片属性”那么......

How can I do this? 我怎样才能做到这一点?

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");

Better late than never! 迟到总比不到好!
The right way is: 正确的方法是:

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

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: 您可以通过测试来检查TImage控件中是否存在位图:

if Image.Picture.Bitmap.Width > 0 then
  // do whatever

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM