-1

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?

Rohit Gupta
  • 4,022
  • 20
  • 31
  • 41
BIBD
  • 15,107
  • 25
  • 85
  • 137

1 Answers1

1

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

 if DBImage1.Picture.Graphic<>nil then 
   //do something
RRUZ
  • 134,889
  • 20
  • 356
  • 483
  • 1
    `TGraphic` also has an `Empty` property, if you want to skip images that are allocated and assigned but otherwise have no data: `if (DBImage1.Picture.Graphic <> nil) and (not DBImage1.Picture.Graphic.Empty) then ...` – Remy Lebeau Sep 18 '15 at 20:55