Link to home
Start Free TrialLog in
Avatar of ChrisBerry
ChrisBerryFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Blob Fields and BlockWrite/Read

Hi,

I am trying to write (and read) the contents of a blob field to a file using BlockWrite.

I am trying to use the following code but it always gives me an I/O Error 87 - what ever that is, errors being documented the way they are.

    ImageStream := TBlobStream.Create(FieldByName('Image') as TBlobField,
      bmRead);
    Blockwrite(TXMessageFile, ImageStream, ImageStream.Size);

Any ideas?

Thanks

Chris

ASKER CERTIFIED SOLUTION
Avatar of vladika
vladika

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of vladika
vladika

If you still want use BlockWrite you can try this

var Buffer: Pointer;
      MemStream: TMemoryStream;
.............
  MemStream := TMemoryStream.Create;
  try
    TBlobField(DataSet.FieldByName('Image')).SaveToStream(MemStream);
    Buffer := MemStream.Memory;
    Blockwrite(TXMessageFile, Buffer^, MemStream.Size);
// use Buffer^ !!!! Stream is not buffer
  finally
    MemStream.Free;
  end;


Avatar of ChrisBerry

ASKER

Thanks,

The reason I am using BlockWrite is because this bit is only part of a file I am creating.

I knew I needed a buffer but could not figure out the details.

Thanks again.

Chris

Hi, Chris

> The reason I am using BlockWrite is because this bit is only part of a file I am creating.

It is not problem. You can use TFileStream for work with
part of file as well as BlockWrite/BlockRead.

Vladika.

Hi Vladika,

>It is not problem. You can use TFileStream for work with
>part of file as well as BlockWrite/BlockRead.

By this do you mean using TFileStream or using 'SaveToFile' method?

I thought 'SaveToFile' always re-wrote the file.

Chris


Hi Chris

You are right. I mean TFileStream of course.
I intend you may use TFileStream instead of conventional file I/O

Vladika

Bought this Q