How to deal with a Blob value that is empty

1
var
  Streamalt, Streamalt2 : TStream;
  Jpegalt, Jpegalt2 : TJPEGImage;
  Bmpalt, Bmpalt2 : TBitmap;

begin
Streamalt := DMretaguarda.QConItem.CreateBlobStream(DMretaguarda.QConItemftpec1, bmRead);
      try
        Jpegalt := TJpegImage.Create;
        Bmpalt := TBitmap.Create;
        Jpegalt.LoadFromStream(Streamalt);
        Bmpalt.Assign(Jpegalt);
        ResizeBitMap(Bmpalt, FItem.foto1.Picture.Bitmap, FItem.foto1.Width, FItem.foto1.Height);
        FItem.foto1.Visible := true;
        Jpegalt.Free;
        streamalt.free;
      except
        FItem.foto1.Visible := false;
        Jpegalt.Free;
        streamalt.free;
      end;
end;

The following code is to read an image in the database (mysql), and play it in a TImage.

What I want is to treat this same field to see if it is empty, and if it is empty, do not send anything to my TImage.

    
asked by anonymous 14.07.2014 / 19:00

1 answer

2
  var
      Streamalt, Streamalt2 : TStream;
      Jpegalt, Jpegalt2 : TJPEGImage;
      Bmpalt, Bmpalt2 : TBitmap;

    begin
if not DMretaguarda.QConItemftpec1.IsNull then
      begin
        Streamalt := DMretaguarda.QConItem.CreateBlobStream(DMretaguarda.QConItemftpec1, bmRead);
          try
            Jpegalt := TJpegImage.Create;
            Bmpalt := TBitmap.Create;
            Jpegalt.LoadFromStream(Streamalt);
            Bmpalt.Assign(Jpegalt);
            ResizeBitMap(Bmpalt, FItem.foto1.Picture.Bitmap, FItem.foto1.Width, FItem.foto1.Height);
            FItem.foto1.Visible := true;
            Jpegalt.Free;
            streamalt.free;
          except
            FItem.foto1.Visible := false;
            Jpegalt.Free;
            streamalt.free;
          end;
      end;
   end;

Then, at the time I posted, and found the answer, it was only a null value.

Follow it for whoever needs it.

    
14.07.2014 / 19:07