问题描述
我的表单上有一个TDBImage控件.
I have a TDBImage control on my form.
用户可以在其中-图片.他们还可以在控件中使用-清除图像.
Users can - images in to it. They can also - 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是否为空(并自行清除数据库字段).但是我似乎找不到找到检测控件是否已被用户-'的方法.
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 -'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是否已被擦除/清空?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!