How to Treat a Blob value that is empty

Asked

Viewed 753 times

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 on a Timage.

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

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;

So, at the time I posted, and I found the answer, I just had to treat a null amount.

It’s still there for those who need it.

  • If the Delphi version is >= 7, you can make use of Unit JPeg in the form, may place on it a TDBImage and connected directly to the field, avoiding all this code.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.