我如何知道我的TDBImage是否已被擦除/清空? [英] How do I tell if TDBImage my has been erased/emptied?

查看:54
本文介绍了我如何知道我的TDBImage是否已被擦除/清空?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的表单上有一个TDBImage控件.

I have a TDBImage control on my form.

用户可以在其中 CTRL - V 图片.他们还可以在控件中使用 CTRL - X 清除图像.

Users can CTRL-V images in to it. They can also CTRL-X in the control to clear the image.

稍后当我尝试将该TDBImage的内容保存为数据库时,会遇到内存访问冲突,尤其是在生成内存流时.

When I later try to take the contents of that TDBImage as save it to my database I get memory access violations, in particular when I generate the memory stream.

自然,我的第一个倾向是在执行此操作之前先查看TDBImage是否为空(并自行清除数据库字段).但是我似乎找不到找到检测控件是否已被用户 CTRL - X '的方法.

Naturally my first inclination is to see if the TDBImage is somehow empty before I do this (and clear the database field my self). But I can't seem to find a way to detect if the control has been CTRL-X'ed by the user.

这是我现有代码(如果有帮助的话)的简明版本.

Here's a very condensed version of what my existing code looks like if it helps.

var
  photo: TDBImage;
  photoValue: TPicture; 
  photoStream: TMemoryStream;
  updateQuery: TOraQuery;
begin
  // ....
  // It gets through here without complaint
  photoValue := photo.Picture;

  // It fails on this line
  photoValue.Graphic.SaveToStream(photoStream);
  updateQuery.paramByName('picture').ParamType := ptInput;
  updateQuery.paramByName('picture').AsOraBlob.LoadFromStream(photoStream);
  updateQuery.ExecSQL;
  // ...
end;

如何检测到一个空的/按CTRL键固定的TDBImage控件?

How can I detect an empty/CTRL-Xed TDBImage control?

推荐答案

您可以检查 Graphic 属性是否为nil,就像这样

You can check if the Graphic property is nil, like so

 if DBImage1.Picture.Graphic<>nil then 
   //do something

这篇关于我如何知道我的TDBImage是否已被擦除/清空?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆