【发布时间】:2011-02-12 15:55:57
【问题描述】:
在我的程序中,表单上有一个 TImage 组件。
在某些情况下,程序必须测试:
如果“有一个图像分配给 TImage 组件的图片属性”那么 ...
我该怎么做?
【问题讨论】:
标签: delphi testing components variable-assignment timage
在我的程序中,表单上有一个 TImage 组件。
在某些情况下,程序必须测试:
如果“有一个图像分配给 TImage 组件的图片属性”那么 ...
我该怎么做?
【问题讨论】:
标签: delphi testing components variable-assignment timage
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");
【讨论】:
if NOT Image.Picture.Empty then DoStuff,因为 OP 要求仅在有图片时运行 DoStuff。
迟到总比不到好!
正确的做法是:
if Assigned(Image1.Picture.Graphic) then ...
【讨论】:
你没有说,但我假设你在谈论 Delphi。
可以通过测试检查TImage控件中是否有位图:
if Image.Picture.Bitmap.Width > 0 then
// do whatever
【讨论】: