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

问题描述 投票:3回答:3

我的程序中的表单上有一个TImage组件。

在某些情况下,程序必须测试:

如果“有一个图像分配给TImage组件的图片属性”那么......

我怎样才能做到这一点?

delphi testing components variable-assignment timage
3个回答
2
投票
if Image1.Picture.Graphic = NIL 
then ShowMessage("There is no image.")
else ShowMessage("Image found.");

如果使用位图,您也可以这样做:

if Image.Picture.Bitmap.Empty then ShowMessage("There is no spoon");

1
投票

迟到总比不到好! 正确的方法是:

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


0
投票

你没有说,但我会假设你在谈论德尔福。

您可以通过测试来检查TImage控件中是否存在位图:

if Image.Picture.Bitmap.Width > 0 then
  // do whatever
© www.soinside.com 2019 - 2024. All rights reserved.