Subject Re: [IBO] Blob-jpeg issues
Author Helen Borrie
At 10:22 AM 6/01/2003 +0000, you wrote:
>Hi there,
>I'm trying to have a jpg graphic field (blob) stored in my db. I've
>read through this and a couple of other newsgroups and I'm on my
>way, but have a coule of questions.
>I can save the jpg into my db using:
> tib_query.Params[0].LoadFromFile(filename);

Yes, that is fine, because the ib_query knows it is a blob field. The
database doesn't know (or care) what is in the blob, just as long as it
gets a blob.

>but I cannot display the image in a TImage component successfully.
>(I'm trying to display it in the AfterScroll event of the dataset)

TImage is designed to paint bitmapped images. What you need to do is
include the jpeg unit in your uses clause and test the TImage to see
whether it is TJPEGImage. There is a worked-through example in the Delphi
help for TJPEGImage.

>I understand I need to stream the blob data into the TImage, but
>their doesn't seem to be a
>TIB_Query.FieldByName('PIC').SaveToStream method,
>as I have seen suggested elsewhere.

Aha! Look at TIB_ColumnBlob. :-))

>I know I can use
>TImage.Picture.SaveToFile, and then load this temp file into the
>TImage, but this seems excessive to me.
>I have a feeling I'm missing something small here, but I'm not too
>familiar with streams yet, and I'm kinda stuck without one!

with MyQuery.Row.ByName('PIC') as TIB_ColumnBlob
do begin
[[[ lotsa good things like LoadFromFile, SaveToFile, AssignTo..

>Is there a tib_query.FieldByName('PIC').SaveToStream method, or
>something similar?

In Native IBO, Jason has taken streams and blobs to a whole new level.

If you are just shuffling images about on the client, think about creating
TMemoryStream as a temporary container. It creates a buffer in memory
which can be completely disposed of once you have stored the blob and
finished displaying the image. While you are playing about with it in e.g.
a TJPEGImage, these non-data-aware image-display controls can
LoadFromStream and SaveToStream (including your TIB_BlobField, of course).

Data aware versions are OK, but you don't always need that overhead. For
example, did you know that blobs never get "updated"? When you commit a
new version of a blob across the wire, it completely replaces the old one,
even to the extent that a new blob-id is created. If you *know* that you
are going to replace the old blob, there will often be conditions where you
don't want to see the old one - it's history before you even start - so
don't fetch it.

Get to know streams. They are STILL one of the coolest things about
Delphi. When the Project JEDI site comes back up (it's currently
undergoing disk surgery) you might be interested in picking up Alan Lloyd's
articles on streams from the Voyager pages there.