TStream and TBlobField

Hi!
I'm working on a database application and there is a blob field that holds a jpeg image. I want to save this image somewhere, so I can display it in TImage even when the database connection is closed. I do the following:
Create the stream when the form is created:

procedure TForm1.FormCreate(Sender: TObject);
begin
form1.db.pic_save:=tstream.Create;
end;

Open the database and try to save the image to the stream:

if not ADOTable1picture.IsNull then
begin
adotable1picture.SaveToStream(form1.db.pic_save);
end;

And here I get: Abstract error. Is it possible to save blobfield to tstream? If not, what is the solution?

Comments

  • : Hi!
    : I'm working on a database application and there is a blob field that holds a jpeg image. I want to save this image somewhere, so I can display it in TImage even when the database connection is closed. I do the following:
    : Create the stream when the form is created:
    :
    : procedure TForm1.FormCreate(Sender: TObject);
    : begin
    : form1.db.pic_save:=tstream.Create;
    : end;
    :
    : Open the database and try to save the image to the stream:
    :
    : if not ADOTable1picture.IsNull then
    : begin
    : adotable1picture.SaveToStream(form1.db.pic_save);
    : end;
    :
    : And here I get: Abstract error. Is it possible to save blobfield to tstream? If not, what is the solution?
    :
    :
    TStream is an abstract class, which forms the basis for the streaming mechanism. If you want to store something in a certain medium, you need to use the correct descendant:
    Memory: TPointerStream
    file: TFileStream
    named-pipe: THandleStream
    socket: TSocketStream
    string: TStringStream
    All these descendants create/open the actual storage medium of their type and subclass a number of properties and methods to make the I/O operations easier. For more info see the help files.
  • : : Hi!
    : : I'm working on a database application and there is a blob field that holds a jpeg image. I want to save this image somewhere, so I can display it in TImage even when the database connection is closed. I do the following:
    : : Create the stream when the form is created:
    : :
    : : procedure TForm1.FormCreate(Sender: TObject);
    : : begin
    : : form1.db.pic_save:=tstream.Create;
    : : end;
    : :
    : : Open the database and try to save the image to the stream:
    : :
    : : if not ADOTable1picture.IsNull then
    : : begin
    : : adotable1picture.SaveToStream(form1.db.pic_save);
    : : end;
    : :
    : : And here I get: Abstract error. Is it possible to save blobfield to tstream? If not, what is the solution?
    : :
    : :
    : TStream is an abstract class, which forms the basis for the streaming mechanism. If you want to store something in a certain medium, you need to use the correct descendant:
    : Memory: TPointerStream
    : file: TFileStream
    : named-pipe: THandleStream
    : socket: TSocketStream
    : string: TStringStream
    : All these descendants create/open the actual storage medium of their type and subclass a number of properties and methods to make the I/O operations easier. For more info see the help files.
    :

    Why don't you simply read it into a TDBImage? And from there you can copy the picture to another TImage with an Assign.


    Image1.Picture.Assign(DBImage1.Picture);






  • : : : Hi!
    : : : I'm working on a database application and there is a blob field that holds a jpeg image. I want to save this image somewhere, so I can display it in TImage even when the database connection is closed. I do the following:
    : : : Create the stream when the form is created:
    : : :
    : : : procedure TForm1.FormCreate(Sender: TObject);
    : : : begin
    : : : form1.db.pic_save:=tstream.Create;
    : : : end;
    : : :
    : : : Open the database and try to save the image to the stream:
    : : :
    : : : if not ADOTable1picture.IsNull then
    : : : begin
    : : : adotable1picture.SaveToStream(form1.db.pic_save);
    : : : end;
    : : :
    : : : And here I get: Abstract error. Is it possible to save blobfield to tstream? If not, what is the solution?
    : : :
    : : :
    : : TStream is an abstract class, which forms the basis for the streaming mechanism. If you want to store something in a certain medium, you need to use the correct descendant:
    : : Memory: TPointerStream
    : : file: TFileStream
    : : named-pipe: THandleStream
    : : socket: TSocketStream
    : : string: TStringStream
    : : All these descendants create/open the actual storage medium of their type and subclass a number of properties and methods to make the I/O operations easier. For more info see the help files.
    : :
    :
    : Why don't you simply read it into a TDBImage? And from there you can copy the picture to another TImage with an Assign.
    :
    :
    : Image1.Picture.Assign(DBImage1.Picture);
    :
    :
    :
    :
    :
    :
    :
    Hi!

    You can use TBlobField as a descandent of Tstream, Be careful of setting transliterate off, for avoiding binary corruption of the data by character coversion rutines in the dataset.

    They you can use CopyFrom to copy the data into another stream

    [code]

    var
    frstream , tostream : TStream;

    begin
    TBlobField(ZReadOnlyQuery2.Fields[i]).Transliterate := false;
    frStream := ReadOnlyQuery2.CreateBlobStream(ZReadOnlyQuery2.Fields[i],bmRead);
    ToStream := TmemoryStream.Create;
    toStream.CopyFrom(frStream,frStream.Size);
    frStream.Free;
    toStream.Free;
    [/code]
    soemthing like this
    You can use TfileSteam insted of TmemoryStream if you want to store in a file, or you can use the Tbitmap.LoadFromStream, then Assign it to TPicture, etc. As your app requires it.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories