Board index » delphi » Reading and Writing Record Type (structure) in BLOB field - Stream read error

Reading and Writing Record Type (structure) in BLOB field - Stream read error

Hey there,

I'm trying to save a record to my blob field in an interbase database, and
then later read it back into another record. Suffering from a stream read
error.

Interbase 6.02
Delphi 6 Enterprise
WinXP

These are the records I'm trying to save:

TBinLabelItem = record
                        Value : String;
                        X,Y,Height,Width : Integer;
                        Visible : Boolean;
                end;

TBinLabel = record
                     Width,Height : Integer;
                     Barcode,
                     Bin_Name,
                     Bin_Type,
                     Bin_Num,
                     Item_Name : TB3_BinLabelItem;
             end;

I use this to save the record into the BLOB. I assume this is working fine,
no exceptions, and there seems to be binary data in the BLOB field.

    Stream.WriteBuffer(BinLabel,SizeOf(BinLabel));
    ParamByName('BINLABEL').LoadFromStream(Stream,ftBlob);

And this to load the record :

 MemStream := TMemoryStream.Create;

 Try

 TBlobField(Query.FieldByName('BINLABEL')).SaveToStream(MemStream);
 MemStream.ReadBuffer(TempBin.BinLabel,MemStream.Size);   <--- Stream read
error here.

 DrawLabel;
 Finally
 Stream.Free;
 End;

Please if anybody knows what I'm doing wrong or a better way to do this
please respond.

Kind regards
Sean B

Ps if possible to e-mail answer to s...@b3solutions.co.za

 

Re:Reading and Writing Record Type (structure) in BLOB field - Stream read error


Quote
Sean Bertinotti wrote:

> I'm trying to save a record to my blob field in an interbase
> database, and then later read it back into another record. Suffering
> from a stream read error.

> These are the records I'm trying to save:

> TBinLabelItem = record
>                         Value : String;
>                         X,Y,Height,Width : Integer;
>                         Visible : Boolean;
>                 end;

> TBinLabel = record
>                      Width,Height : Integer;
>                      Barcode,
>                      Bin_Name,
>                      Bin_Type,
>                      Bin_Num,
>                      Item_Name : TB3_BinLabelItem;
>              end;

You do not show the definition for TB3_BinLabelItem, but I'll assume it's
some number of TBinLabelItems.

Quote
> I use this to save the record into the BLOB. I assume this is working
> fine, no exceptions, and there seems to be binary data in the BLOB
> field.

>     Stream.WriteBuffer(BinLabel,SizeOf(BinLabel));
>     ParamByName('BINLABEL').LoadFromStream(Stream,ftBlob);

The problem is what you are saving includes a string type which is fact only
a pointer to a string in memory. IOW you are not saving the string itself at
all, you are saving only the 4 byte pointer to it.

Quote
> And this to load the record :

>  MemStream := TMemoryStream.Create;

>  Try

>  TBlobField(Query.FieldByName('BINLABEL')).SaveToStream(MemStream);

    MemStream.Position := 0;

Quote
>  MemStream.ReadBuffer(TempBin.BinLabel,MemStream.Size);   <--- Stream
> read error here.

Setting the position back should get you past this error, but you will still
have problems as mentioned regarding the strings begin saved.
--
Wayne Niddery - Logic Fundamentals, Inc. (www.logicfundamentals.com)
Powered by Delphi and IB: http://www.logicfundamentals.com/RadBooks.html
"Democracy, without that guarantee of liberty, is merely a method of
selecting tyrants." - Alan Nitikman

Other Threads