How do I tell if TDBImage my has been erased/emptied?

时光总嘲笑我的痴心妄想 提交于 2019-12-25 18:35:34

问题


I have a TDBImage control on my form.

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

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.

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;

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


回答1:


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

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


来源:https://stackoverflow.com/questions/32656587/how-do-i-tell-if-tdbimage-my-has-been-erased-emptied

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!